Searching \ for '[tech]: c18 structures unions and referencing bits' in subject line. ()
Make payments with PayPal - it's fast, free and secure! Help us get a faster server
FAQ page: www.piclist.com/techref/index.htm?key=c18+structures+unions
Search entire site for: ': c18 structures unions and referencing bits'.

Exact match. Not showing close matches.
PICList Thread
'[tech]: c18 structures unions and referencing bits'
2009\07\21@080800 by Justin Richards

face picon face
In C18 a union can be described as follows

typedef union _IP_ADDR
{
   BYTE        v[4];
   DWORD       Val;
} IP_ADDR;


Then memory may be referenced as follows [after a variable IP of type
IP_ADDR is declared]
i=3;
IP.v[i];

Can a similar member reference be used with bits.

That is instead of referencing a bit member in the union below as

iomask.bits.b0;

Can it be referenced as

iomask.bits[i]; or perhaps iomask.bits.b[i];

Experimenting with the compiler seems to indicate that it is not possible.

Pointers to examples etc would be greatly appreciated or even what to google
for.

     union
       {
           struct
           {
               unsigned char b0:1;
               unsigned char b1:1;
               unsigned char b2:1;
               unsigned char b3:1;
               unsigned char b4:1;
               unsigned char b5:1;
               unsigned char b6:1;
               unsigned char b7:1;
           } bits;
           BYTE val;
       } iomask;

Cheers Justin

More... (looser matching)
- Last day of these posts
- In 2009 , 2010 only
- Today
- New search...