How are the structures in the C programming language really implemented?

Structures are a composite data structure in the C programming language; they consist of primitives, such as ints and pointers, which are placed in memory in an adjacent manner, for example an array.

My question is what are created by the structures themselves? Are they an array type? For example, a hash table can be implemented as an array of linked lists. Similarly, what is the structure implemented like? If necessary, explain at the x86 build level. Thanks.

+5
source share
1 answer

At the assembly level, the structure is reduced to the address to which the offset corresponding to the structure member refers.

Depending on the alignment rule and the memory of the memory class, for example, a structure is allocated.

Example:

struct A { int a, char b }a1; 

In the above case, if you write a1.b = 5 , its build equivalent would be something:

MOV 5 TO ADDRESS OF a1 + 4 // if the integer size is 4

0
source

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


All Articles