当前位置: 动力学知识库 > 问答 > 编程问答 >

c++ - Where to look up GCC's implementation of implementation-defined behavior?

问题描述:

As the C++ standard is very vague on many things, I want to look up the concrete implementations from different compilers. At the moment, I want to know how GCC allocates and aligns bit fields.

In the case of the MS Visual C++ compiler, it is very easy: There is a nice page in the user manual about bit fields which explains all open allocation/alignment questions, and there are even figures and examples.

I just want the same information for GCC, but it seems to be way more complicated. There is a page in the GCC manual which just states "Determined by ABI." Then we have some information about ABI policy and guidelines which contains a link to a document named Itanium C++ ABI on Github. Now, in this document, we can found the following: "the bitfield is allocated as required by the underlying C psABI". And that's the point were I'm stuck. I can find no helpful sites when searching for C psABI.

Can anyone please point me to the site where GCC's implementation of bit fields is described? It can't be that complicated, can't it? Why is GCC's documentation so often so much more complicated then Microsoft's? Am I using the wrong resources?

网友答案:

That is the difference between GCC (which runs on many, many different machines and operating systems, each with their own convention on how to do some things, the platform's ABI) and MS C, which runs on one platform only (essentially). But that is not all, there are other areas where the standard doesn't dictate what to do, in order to give the compiler writer leeway. If the platform doen't mandate anything either, the compiler writer can choose at will. And the selection might even change seemingly at random from one version of the compiler to the next on the same platform. The compiler should document its choices, but for a beast like GCC covering so many platforms it can be a daunting task to find that.

网友答案:

G++ documents this in §4.9 of its manual. On the other hand, the documentation isn't really very helpful, since it says that it is "determined by ABI"; in other words, g++ will do whatever the binary ABI of the platform requires. Thus, under Windows, it will do exactly what Visual C++ would do, under Solaris what Sun CC would do, and under Linux, what g++ would do. And if the latter is somewhat circular... The ABI for C is normally defined by the system, and not the compiler; the compiler just conforms. And I don't know where to find this information for Linux. (Differences in the ABI on the same processor have created so many problems in the past that some chip manufacturers have defined an ABI from the start. This tends to only apply to recent architectures.)

As for GCC's documentation being more complicated than Microsoft's, I've not found that. Neither are particularly complete, often leaving some of the most important issues, like threading, unspecified.

分享给朋友:
您可能感兴趣的文章:
随机阅读: