Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

C++ name mangling.

168 views
Skip to first unread message

Chandrasekhar Thumuluru

unread,
Oct 24, 2014, 12:53:28 PM10/24/14
to
In the following program I want to know why main is not mangled similar to other method:

int main() {}
int main1() {}

If I check the output 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 no effect.

Appreciate your help on this.

Victor Bazarov

unread,
Oct 24, 2014, 1:39:57 PM10/24/14
to
I don't exactly know what you mean WRT #pragma, those are
implementation-specific features. But it probably doesn't matter...

Two things to consider:
a) 'int main()' is a special function. It is likely treated specially
by the implementation.
b) Name mangling is implementation-specific behavior (and actually not
even mentioned by the Standard). What difference does it make whether
it's done, or how it's done?

V
--
I do not respond to top-posted replies, please don't ask

Paavo Helde

unread,
Oct 24, 2014, 1:44:34 PM10/24/14
to
Chandrasekhar Thumuluru <chandra....@gmail.com> wrote in
news:d6b606b9-7558-4da9...@googlegroups.com:
The standard says about the main() function:

"This function shall not be overloaded."

So there is no need to mangle it, and leaving it non-mangled (or more
exactly, mangled by extern "C" conventions) was probably the simplest way
to ensure it works with all linkers.

So, why do you care? What problem are you trying to solve?

Chandrasekhar Thumuluru

unread,
Oct 25, 2014, 5:17:42 AM10/25/14
to
On Friday, October 24, 2014 11:14:34 PM UTC+5:30, Paavo Helde wrote:
> Chandrasekhar Thumuluru wrote in
> news:@googlegroups.com:
>
> > In the following program I want to know why main is not mangled
> > similar to other method:
> >
> > int main() {}
> > int main1() {}
> >
> > If I check the output 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 no effect.
>
> The standard says about the main() function:
>
> "This function shall not be overloaded."
>
> So there is no need to mangle it, and leaving it non-mangled (or more
> exactly, mangled by extern "C" conventions) was probably the simplest way
> to ensure it works with all linkers.
>
> So, why do you care? What problem are you trying to solve?

Thanks for your response. I buy the answer. In fact my understanding was same too.

Here was the confusion I had:
I wrote the above sample and tried to change the program entry point from main() to main1(). With that I was expecting the entry method to be main1() and not main() and hence main() should be name mangled and not main1(). To my surprise it was not the case with g++ compiler I used.

After posting this question I read further and realized #pragma support is compiler dependent. I used -Wunknown-pragmas g++ flag and realized g++ doesn't support #pragma entry. That explains the mangling part.

Truth

unread,
Oct 25, 2014, 12:44:39 PM10/25/14
to
The "difference" is knowledge and understanding. Something that was
loathsome to "The Russian Bunch" who flooded this group and the idiots
who followed them here back in the late-nineties and early two
thousands. And I see the last one left is still at it. Exactly and
precisely the same, no change at all. He's learned nothing.

I remember when Bjarne himself would post here.

I warned repeatedly and loudly back then to stop with that crap and
treating people like crap or this newsgroup would become as dead as
these jerks social lives. And look at this group now. It's a burned-out
stinking fetid ghetto. Extremist freaks arguing... nothing. I was 100
percent right.

Argue against the fact this group is pathetic now and you show how
delusional one can be. Sausages Leigh? For fucks sakes.

But I'm talking to the Continuum aren't I.

Truth

unread,
Oct 25, 2014, 12:54:37 PM10/25/14
to
There was a time when professionals simply answered a question. If they
didn't know, they'd say that or not respond in a newsgroup. They'd leave
it to the professionals. The best engineers I've ever known always
wonder and try to understand their craft, in all its aspects, and would
share the knowledge they worked hard to obtain. Knowledge that may not
seem pertinent at the moment, but it's always useful down the road.

The worst, the absolute worst "engineers" are the ones who say; "Why do
you need to know that? Oh, you don't. Why do you care?" The worst. Avoid
these people. And of course, the irony is these people never even
recognize this trait.

Watch and listen. Here it comes now.

Öö Tiib

unread,
Oct 25, 2014, 1:50:19 PM10/25/14
to
Read your own post above. It is best example of recursion since it
complains about problem that it represents. No information only empty
trash talk.

Paavo Helde

unread,
Oct 25, 2014, 3:06:16 PM10/25/14
to
Chandrasekhar Thumuluru <chandra....@gmail.com> wrote in
news:de22494a-c15c-4fd5...@googlegroups.com:

> Here was the confusion I had:
> I wrote the above sample and tried to change the program entry point
> from main() to main1().

You can probably do that, but it's kind of swimming against the current.
Basically you need to tell the linker the new entry point name and throw
out or redirect any compontents which are expecting 'main'. See e.g.
http://stackoverflow.com/questions/7494244/how-to-change-the-entry-point-
in-gcc and make needed modifications for C++ (like declaring main1 as
extern "C"). Lots of hassle with no gain.

Cheers
Paavo





Paavo Helde

unread,
Oct 25, 2014, 3:09:37 PM10/25/14
to
Truth <It...@IsTruth.com> wrote in news:m2gkjs$ab9$1...@speranza.aioe.org:

> On 10/24/2014 10:44 AM, Paavo Helde wrote:
>
>> So, why do you care? What problem are you trying to solve?
>
> The worst, the absolute worst "engineers" are the ones who say; "Why
> do you need to know that? Oh, you don't. Why do you care?" The worst.
> Avoid these people. And of course, the irony is these people never
> even recognize this trait.

I didn't say he does not need to know. I asked because I suspected (and
rightly so) that his actual worries are elsewhere. Indeed, he wanted to
rename main, but got confused by the name mangling meanwhile.

Cheers
Paavo

chandra_cst

unread,
Oct 27, 2014, 1:54:24 PM10/27/14
to
On Sunday, October 26, 2014 12:36:16 AM UTC+5:30, Paavo Helde wrote:
> chandra_cst wrote in
> 8...@googlegroups.com:
>
> > Here was the confusion I had:
> > I wrote the above sample and tried to change the program entry point
> > from main() to main1().
>
> You can probably do that, but it's kind of swimming against the current.
> Basically you need to tell the linker the new entry point name and throw
> out or redirect any compontents which are expecting 'main'. See e.g.
> http://stackoverflow.com/questions/7494244/how-to-change-the-entry-point-
> in-gcc and make needed modifications for C++ (like declaring main1 as
> extern "C"). Lots of hassle with no gain.
>
> Cheers
> Paavo

Thanks for your response. Actually I was not worried about renaming the main. I was reading some articles related to linkers & loaders and I was writing different samples and was exploring different tools like nm, readelf and so on. During the process I hit this particular example and wondered why main was not mangled though I changed the entry to main1. Later I realized g++ was not honoring the pragma directive I used to change the entry point. Anyways my question is answered and the link you posted helped. Thanks again..!

Erdoeban Zsukloff zu Brecher Zhuang

unread,
Nov 4, 2014, 10:27:07 PM11/4/14
to
>"Truth" wrote in message news:m2gkjs$ab9$1...@speranza.aioe.org...
I find rather repulsive when a legitimate prima facie technical question is
met with derision expressed by "Why do you care?", especially on open forum.
That said, sometimes this very question - "Why do you care?" - does not bear
derisive emotional load, and is a genuine interest in the subject .


---
This email is free from viruses and malware because avast! Antivirus protection is active.
http://www.avast.com


--- news://freenews.netfront.net/ - complaints: ne...@netfront.net ---

DSF

unread,
Nov 7, 2014, 4:55:06 PM11/7/14
to
That's a problem with most text communication: It doesn't convey
the emotions behind the words. Does
"Why do you care?"
mean "That's not important." or "That's none of your concern."
or does it mean "Is this important to your current work, or are you
going off on an unnecessary tangent?

>
>---
>This email is free from viruses and malware because avast! Antivirus protection is active.
>http://www.avast.com
>
>
>--- news://freenews.netfront.net/ - complaints: ne...@netfront.net ---
DSF
"'Later' is the beginning of what's not to be."
D.S. Fiscus

Martijn Lievaart

unread,
Nov 9, 2014, 5:10:15 PM11/9/14
to
On Fri, 07 Nov 2014 16:54:56 -0500, DSF wrote:

> That's a problem with most text communication: It doesn't convey
> the emotions behind the words. Does "Why do you care?"
> mean "That's not important." or "That's none of your concern."
> or does it mean "Is this important to your current work, or are you
> going off on an unnecessary tangent?

Or even a poorly worded "Why would you ever want to do this?" or "I sense
you are solving the wrong problem".

M4
0 new messages