5

On msdn for cl compiler option /Zp, it is mentioned that "Packs structures on 8-byte boundaries (default)." Does that mean that if there a data type of size > 8 bytes, by default (no compiler option or pragma pack) it would not be naturally aligned and rather will have 8 byte alignment. If yes, is that case with GCC/clang?

I checked on GCC, using -fpack-structand __uint128_t, that it does not have any such default. For example sizeof(tStruct) is 32 and 24:

struct tStruct {
uint64_t    a;
__uint128_t b;
};

I am not able to check the same on windows as it does not provide any data type > 8 bytes.

Manolete
  • 3,431
  • 7
  • 54
  • 92
Abhishek Jain
  • 9,614
  • 5
  • 26
  • 40
  • 4
    "Naturally aligned" means "aligned per the CPU recommendations", which means that it primarily makes sense for types that map 1-to-1 to CPU types. `__uint128_t` does not. It's probably synthesized from two 64 bit types. Thus, its natural alignment is that of a 64 bit type. – MSalters Jun 24 '15 at 10:34
  • Natural aligned means size of the data type and in case of __uint128_t it is 16 and hence the sizeof(tStruct) comes out to be 32. – Abhishek Jain Jun 24 '15 at 11:29
  • Well, `int[4]` is a 128 bits type in MSVC++ but I think everyone agrees that its natural alignment is 4 bytes. That said, MSVC++ in fact does have _scalar_ data types which are 128 bits, e.g. `__m128i`. – MSalters Jun 24 '15 at 11:39
  • MSalters is right that it is aligned per the CPU recommendations but GCC implements `__uint128_t` on x86 with SSE2 which requires 16-byte alignment. It may be different on different architectures. – StenSoft Jun 24 '15 at 12:18

0 Answers0