On Fri, 9 Dec 2011 10:39:02 -0800 (PST), Chris Higgs
<
chig...@gmail.com> wrote:
>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>
Hmmm. Is there any reason at all why your variable "mybits"
could not be declared as my_struct_t? it's a packed struct,
so you can still slice-and-dice it like any other vector,
so you don't lose anything by declaring it as the struct type.
The BNF syntax for expressions is quite hard to navigate
manually, but I'm fairly sure you cannot put anything
in front of the element-select '.' except an identifier.
It is tiresome. Another place it's a PITA is when a
function returns a class object or a struct, and you
want to select from the result:
func_returns_struct().element // illegal
Maybe one day... SV-2014???
--
Jonathan Bromley