Using structure expressions as default values without an
explicit cast can lead to unintended results. As there's no
particular benefit to omitting the cast, I propose to add the
following sentence to 7.14 after the first example of using
the default keyword.
"The expression after the 'default' keyword shall not itself
be a structure expression or structure literal unless an
explicit cast is used."
Consider the following example (from Yong Xiao)
module m;
parameter a = 1, b = 2;
typedef struct { byte a, b;} F1;
typedef struct { F1 f1; byte f2 [10:0];} S1;
initial begin
S1 y = {default:{a:20, b:4, default:'0}};
end
endmodule
which would apparently (???) be equivalent to
y.f1.a = 20;
y.f1.b = 4;
y.f2[a] = 20;
y.f2[b] = 4;
y.f2[...other_idx...] = 0;
and is also vulnerable to a change in the parameter names a and b.
-- Brad
>
Received on Sun Apr 11 13:28:52 2004
This archive was generated by hypermail 2.1.8 : Sun Apr 11 2004 - 13:29:07 PDT