문제

I have a question regarding the C++ compiler.

When exactly the C++ compiler will create a common symbol? With a C compiler I could provide common symbols to the object file, but if I compile the very same code with a C++ compiler (GNU), I only get only defined and undefined symbols.

So the question is what circumstances will cause a variable/function to be compiled as common in C++?

도움이 되었습니까?

해결책

Some of them never do. The late and much-lamented Watcom C++ compiler made great use of common symbols to economize on inline function instances. There are various cases of extern that can also be resolved economically in this way.

다른 팁

The primary reason common symbols exist is because of Fortran with its common blocks, and hence the name, "common symbol". The very concept of common symbols is antithetical to C++ and it's rather strict one definition rule. C has a similar rule, but the C standard also recognizes that allowing multiple definitions of the same symbol is a common extension to the language. The C++ doesn't have a "common extensions" appendix. Either a vendor is compliant with the standard or it isn't.

Bottom line: There's no reason for a C++ compiler to generate a common symbol.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top