C++ function names quick question

Programming, for all ages and all languages.
Post Reply
User avatar
Neo
Member
Member
Posts: 842
Joined: Wed Oct 18, 2006 9:01 am

C++ function names quick question

Post by Neo »

I know there is someplace where we can get how C++ functions names (__mainvPcj etc.....) are translated to object code.
I just can't find where (tried googling but I think I was not sure what to search for :)).

Any links/docs would be appreciated. TIA
Only Human
bluecode

Re:C++ function names quick question

Post by bluecode »

The name mangling convention differs from Compiler vendor to Compilervendor imho, but g++ uses this ABI.
Kemp

Re:C++ function names quick question

Post by Kemp »

Hmm... off-topic a bit, but I've noticed a few instances of people using "imho" where it makes no sense. It expands to "In My Honest/Humble Opinion" (the H changes depending who's writing it usually).

If I'm reading a post and I hit something like "The name mangling convention differs from Compiler vendor to Compiler vendor imho" my parser falls over and my reading just kinda stops while it recovers. That's not really something you can have an opinion about, it either does or it doesn't. Maybe you were thinking of something like IIRC (If I Recall Correctly) or AFAIK (As Far As I Know)?

Anyway, the longest post so far in this thread is off-topic, sorry ;)
bluecode

Re:C++ function names quick question

Post by bluecode »

bluecode wrote:The name mangling convention differs from Compiler vendor to Compilervendor afaik, but g++ uses this ABI.
Sorry. Ab jetzt schreibe ich meine Beitr?ge in deutsch, aber ich glaub kaum das dein Parser damit fertig wird 8)
Perhaps that's because if you translate "imho" into german it does make sense in that context, afaik :D
Kemp

Re:C++ function names quick question

Post by Kemp »

Lol, I'm sorry if it sounded like an attack on you, it honestly wasn't. And yes, I'm sure if you wrote in German my parser would fall over even faster ;D

btw, and sorry for going even further off topic, does the meaning of the translated imho change, or is it one of those subtle differences that are destined to cause confusion for the rest of time (or until we all speak Mandarin, whichever comes first)?
bluecode

Re:C++ function names quick question

Post by bluecode »

Kemp wrote:Lol, I'm sorry if it sounded like an attack on you.
nah, no need to be sorry ;)
subtle differences that are destined to cause confusion for the rest of time (or until we all speak Mandarin, whichever comes first)?
Some friend of mine told me that opinion has a different conotation than the german word "die Meinung / das Erachten". In german you don't need an opinion on a topic to say "meiner Meinung nach / meines Erachtens" (german for imo), because if you can't have one, it just means "as far as I know". I wasn't aware of that difference, so thanks for mentioning, that it is wrong :)

And now I'm again sorry... this time for hijacking the thread
User avatar
Neo
Member
Member
Posts: 842
Joined: Wed Oct 18, 2006 9:01 am

Re:C++ function names quick question

Post by Neo »

bluecode wrote: The name mangling convention differs from Compiler vendor to Compilervendor imho, but g++ uses this ABI.
Ah! name mangling, that was what I was looking for (I had forgotten the name since its over 2 years since I used it).
Only Human
User avatar
Neo
Member
Member
Posts: 842
Joined: Wed Oct 18, 2006 9:01 am

Re:C++ function names quick question

Post by Neo »

Ok I had a look.

What I was wanting to do is interface some C++ and ASM code (using NASM).
However for NASM to know the C++ function name I have to use extern "C" { }. But using his means that I cannot use C++ feature such as overloaded functions.

This makes it tedious to interface ASM and C++ code or is there some other way around this?
Only Human
bluecode

Re:C++ function names quick question

Post by bluecode »

Well, I never tried to interface C++ code from assembler, but if you compile your C++ code to some object format and than objdump on it (with all headers displayed) you can find out, which name your C++ Compiler gives your C++ functions. You just take that name (which might of course look very weird, because of the name mangling) and put "extern <yourc++functionname>" into nasm and call that function. But be aware of a different calling convention ;)
mystran

Re:C++ function names quick question

Post by mystran »

You can use a wrapper function, with extern "C", and then call C++ linked code from that small wrapper. The wrapper itself can't be overloaded, but it's still compiled as C++, so it can call other overloaded functions or whatever you want.

Ofcourse you can also make a general wrapper and play with things like function pointers and the so-called visitor pattern if you feel like it.

I would avoid relying at name mangling at all cost. It seems that it gets changed every two years anyway.
Kemp

Re:C++ function names quick question

Post by Kemp »

Isn't there an option in most compilers (by which I mean VC++ and G++ :P ) to turn off name mangling?
mystran

Re:C++ function names quick question

Post by mystran »

Without name mangling there's no overloading, and without overloading there's really no C++. :)
User avatar
Neo
Member
Member
Posts: 842
Joined: Wed Oct 18, 2006 9:01 am

Re:C++ function names quick question

Post by Neo »

Are there any plans to make the name mangling standard?
Only Human
mystran

Re:C++ function names quick question

Post by mystran »

The above mentioned ABI that G++ uses is one such attempt at a standard C++ ABI, including name mangling.

I would expect hell to melt before everyone uses it, though.
Post Reply