Why doesn't GCC optimize structs?

前端 未结 7 1358
耶瑟儿~
耶瑟儿~ 2020-11-28 05:58

Systems demand that certain primitives be aligned to certain points within the memory (ints to bytes that are multiples of 4, shorts to bytes that are multiples of 2, etc.).

7条回答
  •  刺人心
    刺人心 (楼主)
    2020-11-28 06:48

    C compilers don't automatically pack structs precisely because of alignment issues like you mention. Accesses not on word boundaries (32-bit on most CPUs) carry heavy penalty on x86 and cause fatal traps on RISC architectures.

提交回复
热议问题