Page 1 of 1
C++ function names quick question
Posted: Sun May 21, 2006 6:15 am
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
Re:C++ function names quick question
Posted: Sun May 21, 2006 7:11 am
by bluecode
The name mangling convention differs from Compiler vendor to Compilervendor imho, but g++ uses
this ABI.
Re:C++ function names quick question
Posted: Sun May 21, 2006 11:26 am
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
Re:C++ function names quick question
Posted: Sun May 21, 2006 11:36 am
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
Perhaps that's because if you translate "imho" into german it does make sense in that context, afaik
Re:C++ function names quick question
Posted: Sun May 21, 2006 11:58 am
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)?
Re:C++ function names quick question
Posted: Sun May 21, 2006 12:46 pm
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
Re:C++ function names quick question
Posted: Mon May 22, 2006 12:55 am
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).
Re:C++ function names quick question
Posted: Mon May 22, 2006 1:19 am
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?
Re:C++ function names quick question
Posted: Mon May 22, 2006 4:45 am
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
Re:C++ function names quick question
Posted: Mon May 22, 2006 5:52 am
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.
Re:C++ function names quick question
Posted: Mon May 22, 2006 8:10 am
by Kemp
Isn't there an option in most compilers (by which I mean VC++ and G++
) to turn off name mangling?
Re:C++ function names quick question
Posted: Mon May 22, 2006 1:18 pm
by mystran
Without name mangling there's no overloading, and without overloading there's really no C++.
Re:C++ function names quick question
Posted: Tue May 23, 2006 7:59 am
by Neo
Are there any plans to make the name mangling standard?
Re:C++ function names quick question
Posted: Tue May 23, 2006 8:47 am
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.