1

Possible Duplicate:
Why double in C is 8 bytes aligned?

structure s{
    char a;
    double b;
    int c;
}d;

the sizeof d is 24.As it comes out to be double is aligned to 8 byte boundary.Can anybody explain why it is aligned to 8 byte boundary and not 4 byte boundary.I read somehwre that all elements are aligned to there size ? Why is it so

Community
  • 1
  • 1

1 Answers1

1

Alignment is implementation-defined.

When there are alignment requirements for an object type, it is a value less or equal to the size of the object type. The alignment of the type is often the same as the size of the type.

When IEEE-754 is followed double usually corresponds to the IEEE-754 binary64 type which has a size of 8 bytes.

ouah
  • 142,963
  • 15
  • 272
  • 331