M
Mark
Hello:
#define MAX_SIZE 8
enum my_enum
{
VAL1 = 0;
VAL2,
VAL3,
VAL4,
VAL_MAX
};
struct my_struct
{
enum my_enum e;
int w[MAX_SIZE];
};
Can a layout in such structure cause alignment issues on a target platform?
I understand it much depends on a platform, but generally C compiler is
allowed to do padding of structures, so for example on 32 bit machine, where
'int' is 32 bit long:
struct my_struct
{
int w[MAX_SIZE];
}
is aligned (as fas as I understand) so compiler probably won't be doing
anything else with its layout, but adding 'enum my_enum' in the structure
can poptentially get the structure un-aligned on such machine. Should I be
doing anything special to avoid this and should I be avoiding it at all ?
Would be very thankful for clarifications!
Mark
#define MAX_SIZE 8
enum my_enum
{
VAL1 = 0;
VAL2,
VAL3,
VAL4,
VAL_MAX
};
struct my_struct
{
enum my_enum e;
int w[MAX_SIZE];
};
Can a layout in such structure cause alignment issues on a target platform?
I understand it much depends on a platform, but generally C compiler is
allowed to do padding of structures, so for example on 32 bit machine, where
'int' is 32 bit long:
struct my_struct
{
int w[MAX_SIZE];
}
is aligned (as fas as I understand) so compiler probably won't be doing
anything else with its layout, but adding 'enum my_enum' in the structure
can poptentially get the structure un-aligned on such machine. Should I be
doing anything special to avoid this and should I be avoiding it at all ?
Would be very thankful for clarifications!
Mark