name-mangling

What is the effect of extern “C” in C++?

纵然是瞬间 提交于 2019-11-25 21:36:57
问题 What exactly does putting extern \"C\" into C++ code do? For example: extern \"C\" { void foo(); } 回答1: extern "C" makes a function-name in C++ have 'C' linkage (compiler does not mangle the name) so that client C code can link to (i.e use) your function using a 'C' compatible header file that contains just the declaration of your function. Your function definition is contained in a binary format (that was compiled by your C++ compiler) that the client 'C' linker will then link to using the