Question

I have a bit of code which has the following line

  #pragma comment(linker, "/include:_test@12") 

The project which uses this code works fine when I compile the code using C++ Visual Studio 2010 with configuration type 32bit (I am also on a 32 bit windows machine).

I get a link error when I change the machine to 64bit and use x64 configuration which compiling with C++ Visual Studio 2010.

Is C++ name mangling different for 32bit vs 64bit? If so, where can I find the 64bit C++ name mangling conventions?

Was it helpful?

Solution

Yes the name mangling is different between 32 and 64 bit. A reasonable article covering the exact formats can be found here. You can tell the major differences pretty quickly, however, by simply compiling to both targets and examining the resulting map files. From my experience they're almost identical (64bit adds a small datum, potentially changes others).

Simple sample: void foo();

32bit: ?foo@A@@QAEXXZ
64bit: ?foo@A@@QEAAXXZ

For non-mangled std call, the length suffix can be substantially different, depending on the parameter stack usage. The default 64-bit settings for VC++ do not prepend underscores nor does it encode length-suffixes. The following was compiled both 32/64bit configs with pure out-of-the-box settings:

extern "C" int _stdcall func2(int, int, char*);

32bit: _func2@12
64bit: func2

Not much point there, is there.

Completing the circuit, unmangled _cdecl, which does this:

extern "C" int _cdecl func2(int, int, char*);

32bit: _func2
64bit: func2

If it seems like they went out of their way to make you know what you're pulling-in or exporting-out, evidence suggests you're probably correct.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top