Why c++ source code can call c code without the extern "C"? -
here cpp application calling linux c function. compiled , run in linux g++ 4.7. works. not @ c++. heard need declare 'extern "c"' when want call c function c++ source file. why program works ?
#include <unistd.h> #include <iostream> using namespace std; int main(int argc, const char **argv) { rmdir("t"); cout << "hello" << endl; return 0; }
the unistd.h
header file written compatible c++. if inside find like:
#ifdef __cplusplus extern "c" { #endif ... #ifdef __cplusplus } // extern "c" #endif
if you're on platform unistd.h
not protected in manner need use extern "c"
around include.
Comments
Post a Comment