I would like to write struct in certain order, to keep mutual parameters together.
But to apply reorder optimization at compilation to reduce used memory space while minimalizing R/W operations for most struct members.
Code: Select all
struct
{
bool param1_enabled :1;
int param1_value1;
int param1_value2;
bool param2_enabled :1;
int param2_value1;
}
// size: 20
Code: Select all
struct __attribute__(__reorder__) // produces:
{
// ints
int param1_value1;
int param1_value2;
int param2_value1;
// bools
bool param2_enabled :1;
bool param1_enabled :1;
}
// size: 13
I know that, according to C standard, compiler is not allowed to automatically reorder structure, but can I somehow explicitly ask it to do so for particular structure?