1

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++?

cosinus
  • 38
  • 5

2 Answers2

2

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.

user207421
  • 305,947
  • 44
  • 307
  • 483
  • Thanks. I am trying to summarize up the object symbol types, and I would need an example which would complie to common, so I guess I won't be able to provide it in this case. – cosinus May 02 '12 at 09:50
  • @cosinus The example is a an inline function call! – user207421 May 02 '12 at 22:13
2

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.

David Hammen
  • 32,454
  • 9
  • 60
  • 108