C++ 編譯後庫中函式名會變得很長,與 C 生成的不一致!
#if defined(__cplusplus)||defined(c_plusplus)
//#ifdef __cplusplus
extern "C" {
#endif
//·················
//之間是需要指明用C方式編譯的程式碼;原本屬於C++的程式碼
//·················
#if defined(__cplusplus)||defined(c_plusplus)
//#ifdef __cplusplus
}
#endif
上面程式碼的意思是:如果是 C++ 函式或變數,則使用 extern “C”,這樣函式或變數名稱就會以 C 的方式處理。
如果只有一行的話,也可以這樣寫……
extern "C" int add(int x, int y);
#C #C++ #programming