문제

I see some code in C++ using extern "C" at the beginning of the file like this:

#ifdef __cplusplus 
extern "C" {} 
#endif

What does this mean? How does it work?

도움이 되었습니까?

해결책

It's probably not like that, but more like:

#ifdef __cplusplus 
extern "C" {
#endif

//some includes or declarations

#ifdef __cplusplus 
}
#endif

It tells the compiler to use C name mangling for whatever is declared inside the directives.

The way you have it now:

#ifdef __cplusplus 
extern "C" {} 
#endif

is just dead code.

다른 팁

It is used to inform the compiler to disable C++ name mangling for the functions defined within the braces. http://en.wikipedia.org/wiki/Name_mangling

Extern "C" - notify the compiler,that the noted function is compiled in C style.

It specifies a linkage specification.
It tells the linker how to link the code.

It is useful when you want to mix C and C++ code.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top