C++ compiler - common symbols
-
05-06-2021 - |
문제
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.