I know that some structures may or may not add padding between elements.
My current project is reading input from / dev / input files. The binary layout of these files is defined in <linux/input.h>
:
struct input_event {
struct timeval time;
__u16 type;
__u16 code;
__s32 value;
};
Interestingly, this structure is not marked with a packed attribute . This means that the / dev / input files (which are packaged bit by bit) do not guarantee compliance with the same package as the structure. So the logic
struct input_event event;
read(fd, &event, sizeof(event));
Not defined to work in all arches.
Do I have a mistake in my logic? Or is it safe to assume that something is not going to be packed?