Using C linkage

When you give a C++ function a name, this is the name that you will use to call the function in your C++ code. However, under the covers, the C++ compiler will decorate the name with extra symbols for the return type and parameters so that overloaded functions all have different names. To C++ developers, this is also known as name mangling.

If you need to export a function through a shared library (in Windows, a dynamic linked library), you must use types and names that other languages can use. To do this, you can mark a function with extern "C". This means that the function has C linkage and the compiler will not use C++ name mangling. Clearly, you should use this only on functions that will be used by external code and you ...

Get Beginning C++ Programming now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.