M
mrfirmware
Guest
(Disclaimer: I ask this question only as it pertains to testbench
code.)
I seem to remember someone saying some time ago that it is potentially
dangerous to initialize a variable at declaration time, e.g.
if (cond) begin : named_block
some_type var_name = SOME_INIT_VAL;
...
end
So I've been doing a lot of this:
if (cond) begin : named_block
some_type var_name;
var_name = SOME_INIT_VAL;
...
end
Which wastes vertical space making it harder to keep it "all on
screen" when there are many variable declarations followed by
assignments.
My question is, do I need to do this? Is it completely safe and
correct to provide an initial value at declaration time? What if I
initialize with the return value of a function call? We do this in C
(my background for the last 19 years) all the time.
Thanks,
- Mark
code.)
I seem to remember someone saying some time ago that it is potentially
dangerous to initialize a variable at declaration time, e.g.
if (cond) begin : named_block
some_type var_name = SOME_INIT_VAL;
...
end
So I've been doing a lot of this:
if (cond) begin : named_block
some_type var_name;
var_name = SOME_INIT_VAL;
...
end
Which wastes vertical space making it harder to keep it "all on
screen" when there are many variable declarations followed by
assignments.
My question is, do I need to do this? Is it completely safe and
correct to provide an initial value at declaration time? What if I
initialize with the return value of a function call? We do this in C
(my background for the last 19 years) all the time.
Thanks,
- Mark