hello
how I can define the following structure in C code to Flowcode.
The following example gives me compile error, missing bracket.
Flowcode1.c(1364): error: missing right brace
typedef union ELINMINT_MESSAGE_SIZE
{
unsigned char SIZE;
struct
{
unsigned SIZE0:1;
unsigned SIZE1:1;
unsigned SIZE2:1;
unsigned SIZE3:1;
unsigned SIZE4:1;
unsigned SIZE5:1;
unsigned SIZE6:1;
unsigned SIZE7:1;
} SIZEbits;
} ELINMINT_MESSAGE_SIZE;
typedef union and struct
Moderator: Benj
- JonnyW
- Posts: 1230
- Joined: Fri Oct 29, 2010 9:13 am
- Location: Matrix Multimedia Ltd
- Has thanked: 63 times
- Been thanked: 290 times
- Contact:
Re: typedef union and struct
Hello. Try creating the struct as a typedef - I don't know if BoostC supports nested unnamed structures:
Also, unless your code is already written using this I would not recommend using bit-fields for every bit as you can't access them programatically and have to resort to nested 'if' statements or a 'switch' statement. This is an alternative:
The C compiler will have to perform this shift operation anyway for your bit-fields so I'd be surprised if its less efficient.
Cheers,
Jonny
Code: Select all
typedef struct ELINMINT_MESSAGE_BITSIZE
{
unsigned SIZE0:1;
unsigned SIZE1:1;
unsigned SIZE2:1;
unsigned SIZE3:1;
unsigned SIZE4:1;
unsigned SIZE5:1;
unsigned SIZE6:1;
unsigned SIZE7:1;
} ELINMINT_MESSAGE_BITSIZE;
typedef union ELINMINT_MESSAGE_SIZE
{
unsigned char SIZE;
ELINMINT_MESSAGE_BITSIZE SIZEBits;
} ELINMINT_MESSAGE_SIZE;
Code: Select all
#define ELINMINT_MESSAGE_BIT(byte, bit) (((byte) >> (bit)) & 1)
typedef unsigned char ELINMINT_MESSAGE_SIZE;
// Example: SIZE1 = ELINMINT_MESSAGE_BIT(SIZE, 1);
Cheers,
Jonny