1

Having simple file
a.cpp:

//a.cpp
extern const int n = 8;
const int b = 10;

Compiling with:
g++ -c a.cpp -fPIC

And checking with readelf -sw:

Symbol table '.symtab' contains 11 entries:
Num:    Value          Size Type    Bind   Vis      Ndx Name
...
6: 0000000000000004     4 OBJECT  LOCAL  DEFAULT    4 _ZL1b
...
9: 0000000000000000     4 OBJECT  GLOBAL DEFAULT    4 n
...

Why is the b const int name mangled, but the extern global variable const int n name not mangled?

Does standard define this behaviour (not mangling the name) or is it g++ feature?

zoska
  • 1,684
  • 11
  • 23
  • Ever-helpful Wikipedia offers an overview of [Name Mangling In C++](https://en.wikipedia.org/wiki/Name_mangling#Name_mangling_in_C.2B.2B), where you can read about it not being in the standard (for instance). As for why it would mangle a local...I don't know; I skimmed the question too fast and scrolled down and thought b was a function from the table. Must be an answer, though. – HostileFork says dont trust SE Oct 08 '14 at 10:09
  • Already answered mangling is compiler spefific thing; you can read more from that question http://stackoverflow.com/questions/4468770/c-name-mangling-decoder-for-g – PiotrNycz Oct 08 '14 at 10:22

0 Answers0