CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

union inside struct

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
C#R#



Joined: 28 May 2005
Posts: 5

View user's profile Send private message

union inside struct
PostPosted: Mon Feb 06, 2006 5:32 am     Reply with quote

Hi,
I searched this on the form, but don�t see not about the same problem.
look this:

Code:
struct ULong {  union { long LValue;
                        struct { int Lo,Hi; } merged;
                      } UValue;
             };

whell....it�s don�t work, I think that is not possible to put a union into struct.

I can compile in this way:

Code:
struct TMerge { int Lo,Hi;};
 union ULong { Long LValue;
               Struct TMerge merged;
             };

but I would�like to know if I have a way to use the first code. Rolling Eyes

Thanks.
sjbaxter



Joined: 26 Jan 2006
Posts: 141
Location: Cheshire, UK

View user's profile Send private message Visit poster's website

PostPosted: Mon Feb 06, 2006 9:30 am     Reply with quote

The following works for me.

Code:
typedef struct
{
    int32 id;
    int1  rtr;
    int1  ext;
    int   dlc;
    int   priority;
    union CAN_Message_Data
    {
        int   idata[8];
        int16 ldata[4];
        int32 fdata[2];
    } data;
} CAN_Message;


Although a bug introduced in 3.242 causes other variables to be assigned at the same memory location as this structure. Works in 3.236 though !!!

I have informed CCS about this.
_________________
Regards,
Simon.
C#R#



Joined: 28 May 2005
Posts: 5

View user's profile Send private message

PostPosted: Sun Feb 12, 2006 6:35 am     Reply with quote

HI sjbartex,

Yes, I understand, but still the doubt.
I see that we can put a union into struct, but what about the struct into union ?

Confused

Thanks.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group