您的位置:首页 > 其它

编译器对C函数的名字修饰

2015-12-17 04:28 344 查看
假设有个文件如下:

$ cat test.c

int foo(int a)
{
return 1;
}


编译如下:
$ g++ test.c -c
$ nm test.o
00000000 T _Z3fooi


可见, c++ 编译器对名字做了修饰。
再编译如下:

$ gcc -c test.c
$ nm test.o
00000000 T foo


可见, c编译器未对函数名字修饰
现在修改代码如下:

$ cat test.c
extern "C" int foo(int a);

int foo(int a)
{
return 1;
}
编译如下:
$ g++ test.c -c
$ nm test.o
00000000 T foo


可见,此时 g++ 编译器也不对函数名字修饰了。
这是C和 C++代码混合使用的时候,常用的一种方法。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: