Do clang and gcc do the same memory layouts for a given struct definition?

Are gcc and clang to create the same memory layout for a given struct definition?

Obviously, the exact memory layout of structures is not required by the C standard, but gcc and clang can still create the same memory layout for other reasons. Perhaps clang was explicitly designed to make this gcc compatible. Maybe there is another standard that follows, similar to the name change situation and the Itanium ABI.

+3


source to share


3 answers


There is one fundamentally incompatible case: on Windows, since MinGW (GCC) and MSVC are incompatible, clang can only be compatible with one of them at a time (although with a lot of work, you can get them to communicate).



+1


source


Yes, you can rely on Clang and GCC to create the same layout for identical structures. I can't seem to find which layer of the platform stack defines the structure of the struct right now, but this is Clang's stated purpose for Linux - to link with libraries compiled with GCC.



You can refer to the list of incompatibilities between Clang and GCC .

0


source


For simple cases (no bitfields, no passing structures by value or returning them, no C ++) and with the same architecture, the layout is the same. For complex questions (bitpoles, calling conventions) there are some differences, but they are no more than between different versions of GCC, and both compilers try to align their respective ABIs.

While the C and C ++ standards do not define ABIs, there are separate ABI standards for these languages, such as the psABI System System version and its architecture applications, and the Itanium C ++ ABI (which is just a historical name, default Clang / GCC C ++ ABI).

0


source







All Articles