2

In the following program I want to know why main is not mangled similar to other methods:

int main()
{

}

int main1() 
{

}

If I check the out of nm I see the main method is not mangled while main1 is. I tried to change the program entry from main to main1 using #pragma entry but it had not effect.

Appreciate your help on this.

chandra_cst
  • 307
  • 2
  • 13
  • backward compatibility? I guess the linker searches for a not mangled `main`. – Karoly Horvath Oct 24 '14 at 16:57
  • similar to http://stackoverflow.com/questions/10715689/why-name-mangling-isnt-breaking-my-program – Thiyagarajan Oct 24 '14 at 16:57
  • Then why changing the entry point of the program using #pragma entry has no impact on it? – chandra_cst Oct 25 '14 at 05:28
  • based on the suggestions, I did further read on the #pragma behavior. Seems like pragma support is compiler dependent and I found -Wunknown-pragmas flag supported by g++ to see if the pragma is understood by g++ compiler. Seems like compiler doesn't support #pragma entry or #pragma comment(linker...) and so the main() method is not mangled while main1() is in spite of changing the entry point to main1(). – chandra_cst Oct 25 '14 at 08:29

1 Answers1

0

If I check the out of nm I see the main method is not mangled while main1 is.

The main symbol is special in several respects:

  • you can't take its address
  • you can't call it yourself
  • it must not be mangled because the standard C runtime library will call it by unmangled main name.

So it's not mangled because the C++ standard requires that. See also this answer.

Community
  • 1
  • 1
Employed Russian
  • 199,314
  • 34
  • 295
  • 362