Understanding the concept of alignment

Alignment is an integer value defined by an implementation that represents the number of bytes between consecutive addresses at which an object can be allocated.

This concept is a bit unclear. For instance:

struct B { long double d; };
struct D : virtual B { char c; }

When D is a type of a complete object, it will have a subobject of type B, so it must be properly aligned for a long double.

What does it mean? sizeof(long double)is the number of bytes between what <

+4
source share
2 answers

"" , . ( ), , . , 4- , , 4.

, int, 7, , . 8, .

, : T, , ?

++ (, , ). ++ , , .

" a long double", , , , long double. long double 10 (), , , 10.

+6

. , , , .

.

00100000  64 65 66 61 75 6c 74 0a  31 0a 31 0a 31 0a 31 0a  |default.1.1.1.1.|
00100010  32 0a 31 0a 33 0a 30 0a  31 0a 34 0a 32 33 0a 31  |2.1.3.0.1.4.23.1|
00100020  39 0a 31 37 0a 35 0a 32  36 0a 32 34 0a 33 0a 38  |9.17.5.26.24.3.8|
00100030  0a 31 32 0a 31 31 0a 31  30 0a 31 34 0a 31 33 0a  |.12.11.10.14.13.|
00100040  38 32 0a 38 33 0a 38 34  0a                       |82.83.84.|

hexdump . , . , .

0x100000 0x100001 16- ( CPU 16- C). 0x100003 0x100004 , 16- 2 3, 16- - 4 5. 16- , - .

, 64- (8-) 0x100030..100037 64-. 0x100038 .

, . 16- 8 16 , - , ( ). , " " ( ) . .

+1

Source: https://habr.com/ru/post/1548534/


All Articles