Discussion Forum

Union

Next Thread | Thread List | Previous Thread Start a Thread | Settings

DetailsMessage
Read-Only
Author
Robin Shields
Posted
1-Mar-2001 12:57 GMT
Toolset
C51
New! Union

I need to set up the following union type definition in a global header (.h) file

typedef union
{
struct
{
unsigned char App_Data_Type;

//Power on tests
unsigned char DPort_RAM_Fail_Flag :1;
unsigned char EEPROM_Fail_Flag :1;
unsigned char Watchdog_Fail_Flag :1;
unsigned char RAM_Fail_flag :1;
unsigned char Software_Build_Fail_Flag
:1;
unsigned char Backlight_Fail_Flag :1;
unsigned char Over_Temp_Fail_Flag :1;
unsigned char Spare_DV1 :1;

//Routine Flags
unsigned char Invalid_Message_Flag :1;
unsigned char Display_Blank_Flag :1;
unsigned char
Int_Light_Sensor_Fail_Flag :1;
unsigned char Temp_Sensor_Fail_Flag :1;
unsigned char
Ext_Light_Sensor_Fail_Flag:1;
unsigned char Spare_DV2:3;

//Comms Flags
unsigned char CAN_Bus_Off_Flag :1;
unsigned char Rx_Timeout_Error_Flag:1;
unsigned char Segmentation_Error_Flag
:1;
unsigned char Spare_DV3 :5;

//Reprogrammming Flags
unsigned char
Reprogramming_RAM_Fail_Flag :1;
unsigned char Spare_DV4 :7;

//Range checking flags
unsigned char
Time_And_Date_Range_Fail_Flag :1;
unsigned char
Status_Resp_Range_Fail_Flag :1;
unsigned char Spare_DV5 :6;

//Spare bytes
unsigned char Spare_DV6;
unsigned char Spare_DV7;
} tDefault_Variables_Response;

unsigned char bit_field_bytes[7];

} Def_Var;

However after declaring a variable instance

Def_Var_Mem Def_Var;

I get the compiler warning

"error C129 : missing ';' before 'Def_Var'"

Can any one tell me if the mistake is mine or the compilers please.

If the mistake is the compilers is there a workaround.


Read-Only
Author
Dan Henry
Posted
1-Mar-2001 13:31 GMT
Toolset
C51
New! RE: Union
Instead, try:
Def_Var Def_Var_Mem;
--Dan Henry
Read-Only
Author
Robin Shields
Posted
5-Mar-2001 08:59 GMT
Toolset
C51
New! RE: Union
Thank you for your reply,

Yes I do feel a chump,

how ever that was a mistake in my email rather than the code. I am still having the same problem.
Read-Only
Author
Robin Shields
Posted
5-Mar-2001 09:13 GMT
Toolset
C51
New! RE: Union
OOPS

I did make that mistake.

I was the first time I used Unions, however I shouldn't have made this error as I use structures all the time.
Read-Only
Author
Andrew Neil
Posted
5-Mar-2001 09:57 GMT
Toolset
C51
New! RE: Union
Now that you've got it to compile, have you seen the following Keil knowledgebase articles for a couple of gotchas! with bitfields & unions:

GENERAL: UNION INVOLVING A BITFIELD IS THE WRONG SIZE
http://www.keil.com/support/docs/928.htm

C51: BIT FIELD UNIONS DON'T WORK AS EXPECTED
http://www.keil.com/support/docs/1279.htm

Next Thread | Thread List | Previous Thread Start a Thread | Settings