While going through some C code, I encountered statements like
char var1 : num1, char var2: num2;
From the context, it seems like the number i.e. num1
is the byte size.
I am unable to find any explanation.
While going through some C code, I encountered statements like
char var1 : num1, char var2: num2;
From the context, it seems like the number i.e. num1
is the byte size.
I am unable to find any explanation.
This could be part of what is called a bit-field in the C programming language. Bit-fields can only be declared inside a struct, e.g.
struct {
unsigned int flag : 1; /* A one bit flag */
unsigned int value : 5; /* A 5 bit value */
} option;
if (option.flag == 1)
option.value = 7;
About everything on bit-fields is implementation-defined. The intention is to have bit-fields arranged as compact as possible by the compiler. E.g. the above could well fit in one byte.