Re: [sv-bc] Ambiguity with packed struct literals

From: Greg Jaxon <Greg.Jaxon@synopsys.com>
Date: Mon Dec 06 2004 - 12:43:18 PST

Paul Graham wrote:
>>Here are some examples from that proposal --
>>
>> typedef struct packed {shortint x, y;} my_int;
>>
>> int i = my_int'{8'hFA,8'hCE}; // i is assigned 32'h00FA00CE
>> my_int j = '{8'hFA,8'hCE}; // {j.x,j.y} is assigned 32'h00FA00CE
>> my_int k = {8'hFA,8'hCE}; // {k.x,k.y} is assigned 32'h0000FACE
>
>
>
> How about:
>
> typedef struct packed {shortint x, y;} my_int;
> typedef struct packed {bit x; byte y;} your_int;
>
> my_int k = {x:8'hFA,y:8'hCE}; // {k.x,k.y} is assigned 32'h00FA00CE (?)
>
> Is the presence of field names in a concat-like literal sufficient to
> "cast" the literal into being a struct literal? I would guess not,
> since this not mentioned in the amendment. Also, field names by
> themselves don't uniquely determine a struct type. But if not,
> then what is the meaning of the above concat? Is it illegal?
>
> Paul

The presence of keyed field syntax is enough to indicate that the {}s
are aggregate notation and not concatenation. And aggregate notation is
legal when assigning to a packed struct. So this RHS would be legal to
assign to objects of either type (my_int or your_int), and context would
determine the types to which the value 8'hFA and 8'hCE will be cast.

Adding the ' before this curly brace would be legal, and to a
really literate SV user it might reinforce the idea that this is
aggregate notation and that the context must be inspected to determine
what the aggregate type should be.
Received on Mon Dec 6 12:41:42 2004

This archive was generated by hypermail 2.1.8 : Mon Dec 06 2004 - 12:41:53 PST