Why doesn't GCC optimize structs?

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

    GCC is smarter than most of us in producing machine code from our source code; however, I shiver if it was smarter than us in re-arranging our structs, since it's data that e.g. can be written to a file. A struct that starts with 4 chars and then has a 4 byte integer would be useless if read on another system where GCC decided that it should re-arrange the struct members.

提交回复
热议问题