Looking through the TabOS code I came across this neat structure
typedef struct
{
ushort segment_limit_0_15;
ushort base_address_0_15;
uchar base_address_16_23;
unsigned segment_type:4;
unsigned descriptor_type:1;
unsigned dpl:2;
unsigned present:1;
unsigned segment_limit_16_19:4;
unsigned available:1;
unsigned zero:1;
unsigned default_operation_size:1;
unsigned granularity:1;
uchar base_address_24_31;
} NOALIGN segment_descriptor
How is it that he can define variables with no type? Is it a gcc extension or something. I see that the NOALIGN actually is a __attribute__ ((pack)) that specifies the structure should use the minimum amount of space possible. Hence it comes out to 4 words as required, assuming that the untyped unsigned variables are bits. (which fits into how they are defined with the colon: and # of bits to use)
But where is this kind of syntax documented??
Thanks
Question about C Struct (from TabOS)
Re:Question about C Struct (from TabOS)
These are bitfields and are part of the C language. However, C does not guarantee any specific ordering of the bitfields within machine words, so your code will be machine- and compiler-specific.
Re:Question about C Struct (from TabOS)
Also, just as it is possible to use [tt]short[/tt] and [tt]long[/tt] as a shorthand for [tt]short int[/tt] and [tt]long int[/tt], respectively, it is possible to use [tt]unsigned[/tt] with an implied type of [tt]int[/tt].