C
Chris Higgs
Guest
Greetings,
Is there a legal way to access a member of a structure after a cast?
For example, given the structure:
<code>
typedef struct packed {
logic [7:0] byte_member;
logic flag_member;
} my_struct_t;
my_struct_t mystruct;
logic [$bits(my_struct_t)-1:0] mybits;
logic [7:0] mybyte;
</code>
I would expect to be able to access the structure members like so:
<code>
// This doesn't work, is apparently a syntax error.
mybyte = my_struct_t'(mybits).byte_member;
</code>
However to get VCS to play ball I have to cast to an intermediate
variable first and then access the member:
<code>
mystruct_temp = my_struct_t'(mybits);
mybyte = mystruct_temp.byte_member;
</code>
This is ugly and means I have to create unwanted variables just to
pull fields out of my structure. There must be a better way which I'm
missing...
I can't seem to find anything in the LRM regarding this and the books
I have consulted do not cover it. Any suggestions greatly appreciated.
Thanks,
Chris
Is there a legal way to access a member of a structure after a cast?
For example, given the structure:
<code>
typedef struct packed {
logic [7:0] byte_member;
logic flag_member;
} my_struct_t;
my_struct_t mystruct;
logic [$bits(my_struct_t)-1:0] mybits;
logic [7:0] mybyte;
</code>
I would expect to be able to access the structure members like so:
<code>
// This doesn't work, is apparently a syntax error.
mybyte = my_struct_t'(mybits).byte_member;
</code>
However to get VCS to play ball I have to cast to an intermediate
variable first and then access the member:
<code>
mystruct_temp = my_struct_t'(mybits);
mybyte = mystruct_temp.byte_member;
</code>
This is ugly and means I have to create unwanted variables just to
pull fields out of my structure. There must be a better way which I'm
missing...
I can't seem to find anything in the LRM regarding this and the books
I have consulted do not cover it. Any suggestions greatly appreciated.
Thanks,
Chris