A
aleksa
typedef struct { // 16 bits, one WORD
unsigned short B4:4; // (using GCC)
unsigned short B9:9;
unsigned short B1:1;
unsigned short B2:2;
} S1;
typedef struct {
S1 q1, q2;
} S2;
static S2 table[2]= {
{{1,1,1,1}, {1,1,1,1}}, // just test values
{{1,1,1,1}, {1,1,1,1}}
};
unsigned short getq1 (int i)
{
unsigned short bit16;
// ERROR HERE
// aggregate value used where an integer was expected
bit16 = (unsigned short) table.q1;
return bit16;
}
Someone has already suggested using unions,
typedef struct {
unsigned short B4:4;
unsigned short B9:9;
unsigned short B1:1;
unsigned short B2:2;
} BitField;
typedef union {
BitField bits;
unsigned short all;
} S1;
typedef struct {
S1 q1, q2;
} S2;
but I don't know how to initialize the table:
static S2 table[2]= {
{{1,1,1,1}, {1,1,1,1}}, // just test values
{{1,1,1,1}, {1,1,1,1}}
};
That doesn't work anymore, i get
"missing braces around initializer"
unsigned short B4:4; // (using GCC)
unsigned short B9:9;
unsigned short B1:1;
unsigned short B2:2;
} S1;
typedef struct {
S1 q1, q2;
} S2;
static S2 table[2]= {
{{1,1,1,1}, {1,1,1,1}}, // just test values
{{1,1,1,1}, {1,1,1,1}}
};
unsigned short getq1 (int i)
{
unsigned short bit16;
// ERROR HERE
// aggregate value used where an integer was expected
bit16 = (unsigned short) table.q1;
return bit16;
}
Someone has already suggested using unions,
typedef struct {
unsigned short B4:4;
unsigned short B9:9;
unsigned short B1:1;
unsigned short B2:2;
} BitField;
typedef union {
BitField bits;
unsigned short all;
} S1;
typedef struct {
S1 q1, q2;
} S2;
but I don't know how to initialize the table:
static S2 table[2]= {
{{1,1,1,1}, {1,1,1,1}}, // just test values
{{1,1,1,1}, {1,1,1,1}}
};
That doesn't work anymore, i get
"missing braces around initializer"