|

楼主 |
发表于 2005-1-10 11:05:15
|
显示全部楼层
我看了下面的这个例子:
// specifying_linkage2.cpp
// Declare printf with C linkage.
extern "C" int printf( const char *fmt, ... );
// Cause everything in the specified header files
// to have C linkage.
extern "C"
{
// add your #include statements here
#include <stdio.h>
}
// Declare the two functions ShowChar and GetChar
// with C linkage.
extern "C"
{
char ShowChar( char ch );
char GetChar( void );
}
// Define the two functions ShowChar and GetChar
// with C linkage.
extern "C" char ShowChar( char ch )
{
putchar( ch );
return ch;
}
extern "C" char GetChar( void )
{
char ch;
ch = getchar();
return ch;
}
// Declare a global variable, errno, with C linkage.
extern "C" int errno;
int main()
{
}
例子应该是在cpp文件里的,上面的各种方法我都试过了,就下面这个可以
extern "C"
{
// add your #include statements here
#include <stdio.h>
}
别的加上编译就出问题,搞不懂到底怎么回事。 |
|