Unions are not supported by lite-C. Union members of the same type can be substituted by a #define; union members of different type can be treated as different members of the struct. Example:
Code:
typedef struct S_UNION {
int data1;
union { int data2; float data3; };
union { int data4; int data5; };
} S_UNION; // C/C++
typedef struct S_UNION {
int data1;
int data2;
float data3;
int data4;
} S_UNION; // lite-C
#define data5 data4;
If the struct size must not change, or if the program requires different variable types to occupy the same place in the struct, a special conversion function can be used to convert the type of a variable without converting the content:
Code:
typedef struct S_UNION {
int data1;
union { int data2; float data3; };
} S_UNION; // C/C++
...
S_UNION s_union;
s_union.data3 = 3.14;
typedef struct S_UNION {
int data1;
int data2;
} S_UNION; // lite-C
...
int union_int_float(float x) { return *((int*)&x); }
...
S_UNION s_union;
s_union.data2 = union_int_float(3.14);