extern-c

    6热度

    2回答

    为什么不应该extern "C"对于需要被定义为C函数的函数来指定?将文件编译为C源代码时对编译器有什么影响? 如果在C编译器没有任何影响,我们不能只通过删除#ifdef __cplusplus检查定义如下头文件中的函数? extern "C" { int MyFunc(); } An answer to another question说,#ifdef是需要的,但我不明白为什么:

    18热度

    2回答

    我经常遇到C头文件,其中包含extern "C"后卫, 但不包含任何实际功能。例如: /* b_ptrdiff.h - base type ptrdiff_t definition header */ #ifndef __INCb_ptrdiff_th #define __INCb_ptrdiff_th #ifdef __cplusplus extern "C" { #endif

    17热度

    3回答

    从C++ 11草案,7.5(第1段): 两种功能类型的具有不同语言 键是不同的类型,即使它们是其它方面相同。 因此,我可以根据语言的联系做超负荷: extern "C" typedef void (*c_function)(); typedef void (*cpp_function)(); void call_fun(c_function f) { } void call_fun(c

    0热度

    1回答

    我在Windows 7 Visual Studio 2010中编译旧的MFC WIN CE嵌入式项目时出现问题。我相信旧的应用程序是在嵌入式Visual Studio 4中编译的并且需要mfcce211.dll。 任谁,所有的源文件的管理编译罚款,但我得到以下链接器错误: error LNK2019: unresolved external symbol _VirtualCopy referenc

    2热度

    3回答

    我有一个头文件,我想从.c和.cpp文件中包含。 所以我知道名字改编和extern“C”如此... #ifdef __cplusplus extern "C" { int isPrime(int64_t p); } #endif 但是当我包括这在.c文件也没有看到因为#ifdef __cplusplus 功能 所以后来我最终作出2份: #ifdef __cplusplus

    6热度

    4回答

    为了在C文件中使用C++代码,我读了我们可以只做extern "C" { (where the c++ code goes here)},但是当我尝试使用cout打印某些内容时,我不断收到错误,因为它不识别该库。我认为我只是困惑于如何extern“C”允许您使用C++中的C++代码。

    2热度

    1回答

    我有一个巨大的C工程。 现在我需要一个C++函数来填充一些变量。 将函数声明为extern“C”,从C项目中调用函数是没有问题的。 问题是,我需要传递一个指向C++函数的指针,并且在函数中,我想为指针赋值。 但正是在这一点上,程序崩溃与“分段错误”。 有没有办法让这项工作?还是不可能在C和C++之间以这种方式使用指针? 调用在C功能线程: Restwo = pthread_create(&num,

    5热度

    6回答

    我知道如何使用extern "C"但是您必须使用它的条件是什么? extern "C"告诉C++编译器不执行任何名称重整上 大括号内的代码。这使您可以在C++中从 调用C函数。 例如: #include <string.h> int main() { char s[] = "Hello"; char d[6]; strcpy_s(d, s); } 虽然这

    0热度

    2回答

    如果我使用铛3.8.1编译: extern "C" { int foo(int x) { register int y = x; return y; } } int main() { return foo(123); } 我得到警告: a.cpp:3:18: warning: 'register' storage class specifier is deprecated and in

    0热度

    1回答

    我有一个cpp代码,我想调用一个c函数。 两种编译很好的.o文件,但是当铛++的编译执行,我收到以下错误: file.cpp:74:12: error: expected unqualified-id extern "C" ^ 在CPP文件中的代码如下: void parseExtern(QString str) { #ifdef __cplusplus ex