View previous topic :: View next topic |
Author |
Message |
C#R#
Joined: 28 May 2005 Posts: 5
|
union inside struct |
Posted: Mon Feb 06, 2006 5:32 am |
|
|
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.
Thanks. |
|
|
sjbaxter
Joined: 26 Jan 2006 Posts: 141 Location: Cheshire, UK
|
|
Posted: Mon Feb 06, 2006 9:30 am |
|
|
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
|
|
Posted: Sun Feb 12, 2006 6:35 am |
|
|
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 ?
Thanks. |
|
|
|