| You are here: | About>Computing & Technology>C / C++ / C#> Getting Started> LIst of Calling Conventions and Mangling Names in C++ |
![]() | C / C++ / C# |
LIst of Calling Conventions and Mangling Names in C++Linking SafelyList of Calling ConventionsThe main ones are listed below. The parameters A,B and C referred to are in this function declaration :function f(A, B,C)
Name Mangling in C++Because C++ is a type safe language and fairly strict about types, it introduced name mangling. This means that the exported function includes extra characters derived from the type of parameters. This helped prevent functions being called with the incorrect number of parameters, something that can lead to mysterious crashes. However it can cause problems when non C++ code calls C++ functions. Eg say you have a C# application calling C+= code in a dll. With the functions names mangled in the dll, the functions can't be found. The operating system might be expecting a function called GetValue(int a, float b) but in the dll the name will be mangled and look something like GetValueif.There's a simple fix. Any C++ dll must put this code before and after the declarations of any exported functions. You have something like this in the header file. #define MYEXPORT __declspec(dllexport)The line #define MYEXPORT __declspec(dllexport)tells the compiler to add the __declspec bit to any function defined with MYEXPORT. This makes that function visible to any application that uses the dll. The macro __cplusplus is only defined in Ansi 98 compatible C++ compilers so the macro is ignored in any header file that is included from a C file. In the opposite case where you have C code that you wish to be linked from C++ then you wrap the declarations with a extern "C++" {around your declarations. This forces the compiler to mangle the function names. Full details of what exactly goes on in name mangling are here. You can see examples of dll code for both C and C++ examples provided for the Ongoing Programming Challenge #1 (Rock Scissors and Paper). Both examples use the same header file. |
Las Vegas on a BudgetFind a BargainHotel DealsCheap EatsFree AttractionsEntertainment for Less |
All Topics | Email Article | Print this Page | | ![]() |
| Advertising Info | News & Events | Work at About | SiteMap | Reprints | Help | Our Story | Be a Guide |
| User Agreement | Ethics Policy | Patent Info. | Privacy Policy | ©2008 About, Inc., A part of The New York Times Company. All rights reserved. |


