Why doesn't GCC optimize structs?

前端 未结 7 1353
耶瑟儿~
耶瑟儿~ 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:34

    Structs are frequently used as representations of the packing order of binary file formats and network protocols. This would break if that were done. In addition, different compilers would optimize things differently and linking code together from both would be impossible. This simply isn't feasible.

提交回复
热议问题