Confusion over data structure binding?

Code 1: -

struct emp
{
  char a;
  double b;
};
int main()
{
    struct emp e;
    printf("%p    %p", (void*)&e.a, (void*)&e.b);
}

Output on my computer: -

OO28FF00    0028FF08

Since size charand doubleis equal to '1' and '8' respectively, and therefore, 0028FF00and 0028FF08are multiples of "1" and "8" respectively.

Code 2: -

struct emp
{
  char a;
  long double b;
};
int main()
{
    struct emp e;
    printf("%p    %p    \n", (void*)&e.a,(void*)&e.b);
}

Output: -

0028FF00    0028FF04

Since the size charand long doubleis equal to '1' and '12', respectively, but 0028FF04not a multiple of "12".

Why is the supplement not applicable in this case?

+3
source share
3 answers

A long double 80- , 10 . 10 , , , 32- Intel 12 . 12 4, 32 (3 32 ). , 32- 4 , 12 4 . , , , .

, ... , C ( int32_t, uint64_t .. , , ...)

- , 64- - 16 . 6 ... 64.

+3

:

x86 , . , , .

@LưuVĩnhPhúc . long double 12 (GCC?), 4 , 512- 512 ; . , GCC, double, ( 7 ).

+2

, , , . , , "-" , , ( -O -O ..), , , , . GCC CLang __packed__ , MSVC #pragma pack. . pragma pack (1), __attribute__ ((aligned (1)))

0

All Articles