Skip to main content
GameDev.net gamedev.net
🔒 Locked

Linking with different calling convention

Started by Prune Dec 20, 2010 at 3:04 PM 3 replies 1.1k views
Original Post
Prune
Prune
If I enable /Gr in MSVC for my C++ project, which changes the default calling convention to __fastcall (does this matter in 64-bit BTW? it's still an option when I compile to a 64-bit target) then I have a problem calling the functions of a C library that was compiled without this option (I cannot recompile that library).

The library's headers are included in an extern "C" {} block but that doesn't help as I see the linker looking for functions with an @ prefix which indicates it's assuming __fastcall for those.

How can I override the calling convention for this C library without editing its header files and inserting an __cdecl in front of every function in them? I'm looking for a pragma or some other way to make the compiler not assume __fastcall for those library functions. Obviously, I want to also avoid having to remove /Gr and putting explicitly a __fastcall in front of every one of my functions, as there are several hundred of them.
"But who prays for Satan? Who, in eighteen centuries, has had the common humanity to pray for the one sinner that needed it most?" --Mark Twain

~~~~~~~~~~~~~~~Looking for a high-performance, easy to use, and lightweight math library? http://www.cmldev.net/ (note: I'm not associated with that project; just a user)
SiCrane
SiCrane
According to the MSDN page for __fastcall "On Itanium Processor Family (IPF) and AMD64 machines, __fastcall is accepted and ignored by the compiler...."
Prune
Prune
Thanks, that solves my second question. However, I still wonder about the other as I'm targeting both 32 and 64.
"But who prays for Satan? Who, in eighteen centuries, has had the common humanity to pray for the one sinner that needed it most?" --Mark Twain

~~~~~~~~~~~~~~~Looking for a high-performance, easy to use, and lightweight math library? http://www.cmldev.net/ (note: I'm not associated with that project; just a user)
Nitage
Nitage
* You could add the __cdecl keyword to the functions in the header.
* You could wrap the library so that the header is only included in a single translation unit which doesn't use __fastcall as the default.

I appreciate that neither option is especially practical, but I can't hink of any other way.
Prune
Prune
Too bad there's no pragma to override the setting for a specific block of code...
In the end I simply gave up on __fastcall as most of my functions are class methods and they're always __thiscall anyway.
"But who prays for Satan? Who, in eighteen centuries, has had the common humanity to pray for the one sinner that needed it most?" --Mark Twain

~~~~~~~~~~~~~~~Looking for a high-performance, easy to use, and lightweight math library? http://www.cmldev.net/ (note: I'm not associated with that project; just a user)

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.