Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Accessing a structure member after a cast
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  2 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Chris Higgs  
View profile  
 More options Dec 9 2011, 1:39 pm
Newsgroups: comp.lang.verilog
From: Chris Higgs <chiggs...@gmail.com>
Date: Fri, 9 Dec 2011 10:39:02 -0800 (PST)
Local: Fri, Dec 9 2011 1:39 pm
Subject: Accessing a structure member after a cast
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


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Jonathan Bromley  
View profile  
 More options Dec 24 2011, 5:52 am
Newsgroups: comp.lang.verilog
From: Jonathan Bromley <s...@oxfordbromley.plus.com>
Date: Sat, 24 Dec 2011 10:52:39 +0000
Local: Sat, Dec 24 2011 5:52 am
Subject: Re: Accessing a structure member after a cast
On Fri, 9 Dec 2011 10:39:02 -0800 (PST), Chris Higgs

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


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »