RE: [Dev-C++] Couldn`t link MinGW DLL to MSVC program
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: Per W. <pw...@ia...> - 2005-04-13 20:24:23
|
One addendum. The C++ standard requires name mangling, since the language support multiple functions with the same name but different parameter signatures, such as: int add(int a,int b); doule add(double a,double b); Complex& add(Complex& a,Complex& b); C compilers knows that functions already have unique names, so they can ignore parameter count, parameter types etc. However, some compilers can add extra name mangling to mark functions compiled with non-compatible calling conventions. If you build one C file with all functions taking the parameters in processor registers and a second C file with all functions sent on the stack, a program would fail if a function in one file calls a function in the other file. If the compiler for example adds a $ at the end of the names of all functions built with register calling convention, then the linker will automatically fail to link such a program and you avoid creating a badly broken application. So in short - there _can_ exist C name mangling, but it is for a different reason and it isn't because of parameter count/types but to detect incompatible compiler optimization rules. Some of these compilers have also added non-standard keywords to for example specify: __regcall int add(int a,int b); to inform that a specific function has a specific calling convention different from the one used in the normal C libraries. /Per W On Wed, 13 Apr 2005 Mat...@Ve... wrote: > Thanks for the heads-up, Per. I was getting really confused before, hehe! > > -----Original Message----- > From: Per Westermark [mailto:pw...@ia...] > Sent: Wednesday, April 13, 2005 12:57 PM > To: Mat...@Ve... > Cc: ja...@ya...; dev...@li... > Subject: RE: [Dev-C++] Couldn`t link MinGW DLL to MSVC program > > > That is correct - no name mangling for C. But you may still get some extra > characters in the names. The normal is that you get a leading '_' for all > external C symbols but to my knowledge there exists environments where a > '$' first or last might be used. The leading '_' was added to place the C > symbols in their own "namespace" to avoid name collisions with operating > system symbols, i.e. open is a OS function while _open is the function > available in the C standard library and called by the C code. > > /Per W |