18

I'm trying to develop a dynamic library in C++ to be called by an existing program written in IDL (Interactive Data Language). I know that I need to use extern "C" to disable name mangling so that IDL can call the functions it needs (the rest of the calling mechanism is pretty straightforward).

However, I'm always hesitant to use features of a language that I don't fully understand, so my question is this: What features of C++ do I lose by reverting to C linkage, if any? Namespaces would be an obvious one, I think, but does it completely disable all the other nice features of C++ too? Can I still use the C++ STL, and all the various language features (especially C++11 ones) that I've come to rely on? Or am I stuck essentially coding in C?

m0nhawk
  • 22,980
  • 9
  • 45
  • 73
user1871183
  • 439
  • 5
  • 11
  • Take a look at [C++ Name Mangling](http://en.wikipedia.org/wiki/Name_mangling). You won't be able to do function overloading with `extern "C"`. – Mysticial Dec 02 '12 at 23:22
  • Thanks :) But can I still use the other features of C++, or does everything in the function have to be strictly C? For example, can I use keywords like "del", lambdas, or the existing C++ standard libraries? – user1871183 Dec 02 '12 at 23:27
  • It (everything under the `extern "C"` section) has to be strictly C because it has to be compatible with C. Hence "extern C" – Mysticial Dec 02 '12 at 23:28
  • 1
    "I'm always hesitant to use features of a language that I don't fully understand" Few people could write much C++ if they didn't use features they didn't fully understand... ;) – bames53 Dec 03 '12 at 00:23

1 Answers1

19

The only thing that gets dropped is name mangling of externally visible names. Function overloading by parameter types, as well as by parameter count, stop working as the result. Essentially, name resolution during the linking phase goes back to the plain old C mode (i.e. one name - one entry).

As far as the internals of your implementation go, you can continue using the standard library and all the other nice features of C++11. Only the names of externally visible entities get changed by extern C.

Sergey Kalinichenko
  • 714,442
  • 84
  • 1,110
  • 1,523