Creating DLLs using C++ not C?
C syntax is largely a sub-set of C++ syntax, so often code written in C
is perfectly valid C++. However, sometimes the differences can bite.
For example, C++ allows function overloading, C does not. As the same
function name can now have several sigitures, something has to provide
a hint to the system which particular function you are trying to call.
The accepted solution for this is 'name-mangling' so that the 'real'
name of your function that the linker sees is based on the name you
supplied, along with some hacky symbols that encode the argument names.
Now if you want that function to be exported through a DLL it will
still work, but to import and use it you need to use the mangled name.
The solution built into the language for this problem is to use 'C
linkage' for the function, not C++. That is what the little bit of
pre-processor magic is doing at the top of your header. It spots you
are using a C++ compiler (using a predefined macro required by ISO
standard, so this technique is portable) and declares that all the
following functions are to use the C conventions. They can still be
implemented in C++, using all your favourite C++ features, but can also
safely be called by anything that knows the C calling convention.
AlisdairM(TeamB)
|