0

I want to know if I had such a construction:

typedef struct {
    char element;
} element_t;

So now is the condition:

sizeof(elem.element) == sizeof(element_t) == 1

true only for some architectures or it is always like that? I mean, any alignment can occur here, so can it be:

(sizeof(elem.element) == 1) != (sizeof(element_t) == 4)

if data in structures are aligned to 4-byte boundaries in a 32-bit architecture.

Jonathan Leffler
  • 730,956
  • 141
  • 904
  • 1,278
stanleysts
  • 41
  • 3

1 Answers1

2

sizeof(elem.element) is guaranteed to be 1 (but there is no guarantee that it will hold only 8 bits).

There is no guarantee that sizeof(element_t) == 1, though on all practical architectures, I believe it will be of size 1.

Jonathan Leffler
  • 730,956
  • 141
  • 904
  • 1,278
  • Supporting Jon's answer: http://stackoverflow.com/questions/2215445/are-there-machines-where-sizeofchar-1 – codnodder Dec 02 '13 at 00:27