Why is it sometimes 4 bytes and in other cases 32 bytes?
As soon as the executable file is loaded into memory, it is addressed through the virtual addresses of the process. Alignment restrictions relate to virtual addressing. For example, if you look at the elf man page, check out the description for sh_addralign. It is for this reason that various elf objects set different alignment requirements. You can experiment by changing the source for a.out to turn on double and see if the alignment changes.
Note. This only applies to memory alignment. There is an alignment restriction for the actual file on disk. What for? I think this will help simplify the mapping of data files with inline structures after reading the file. Others can correct me if I am wrong here.
Update: I would like to clarify one problem. Alignment of virtual addresses is necessary only because of the depth of access to the basic memory access set by the chipset. Thus, the same program compiled for different architectures can lead to restrictions on the difference.
source share