简体   繁体   中英

Whether g++ declares a name of C Standard Library as extern “C” linkage or extern “C++”?

As per ISO_14882_2014, section-[17.6.2],

Whether a name from the C standard library declared with external linkage has
extern "C" or extern "C++" linkage is implementation-defined. It is 
recommended that an implementation use extern "C++" linkage for this purpose.

As this is an implementation-defined behavior, I am looking into g++ document for this but nothing is there.

What linkage g++ has for C standard library functions? I checked whether the name is getting mangled for any function or not.. And found it is not. So does that mean g++ has extern "C" linkage?

That would depend on the standard library you are using, not the compiler.

Typically, with g++ you will be using libstdc++ , ie the GNU C++ Library (which in turn relies on glibc , ie the GNU C Library). This one, by default, looks like it uses C linkage for the C names. If you look into the sources themselves, you will currently see 4 different sets of C headers that may be used.

In any case, you shouldn't be relying on that, and it also may change with no warning, even between releases.

Ideally, if you need the exported name for some reason (whether mangled or not), you should directly pick it up from the shared object or from the headers your compiler is using, instead of relying on a given linkage.

Having said that, the major standard libraries/compilers provide them as extern "C" , even MSVC on Windows; and even if you use the C++ cname headers (the ones in the global namespace, of course).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM