Consider this code:
#include <stdio.h>
#include <stdint.h>
#ifdef __GNUC__
#define PACK( __Declaration__ ) __Declaration__ __attribute__((__packed__))
#endif
#ifdef _MSC_VER
#define PACK( __Declaration__ ) __pragma(pack(push, 1)) __Declaration__ __pragma(pack(pop))
#endif
PACK(struct S
{
uint8_t f0;
uint32_t f1;
uint32_t f2 : 17;
});
int main()
{
printf("%zu\n", sizeof(struct S));
return 0;
}
No compiler options were given.
Output:
gcc (9.2.0): 8
clang (8.0.1): 8
cl (19.23.28106.4 for x86): 9
Why in case of cl
result of sizeof
is 9?
What the standard says?