编译器对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++代码混合使用的时候,常用的一种方法。
$ 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++代码混合使用的时候,常用的一种方法。
相关文章推荐
- ASA防火墙疑难杂症解答
- Project5&6 Verilog开发流水线CPU
- Is the type of “pointer-to-member-function” different from “pointer-to-function”?
- LeetCode "Maximum Product of Word Lengths"
- 关于大型网站技术演进的思考(二)--存储的瓶颈(2)
- C ++排序函数sort(),qsort()
- iis7设置dz论坛url静态化经验
- android自带标题样式
- 字典管理表空间 本地管理表空间 之间的区别(未懂)
- [LeetCode317]Shortest Distance from All Buildings
- [leetcode] 84. Largest Rectangle in Histogram 解题报告
- iGrimace V8 简单的安装方式
- python 线程及线程池
- 普法知识(40):宣传行政复议法的重要性
- 人品计算器
- [leetcode] 85. Maximal Rectangle 解题报告
- Apache页面压缩配置问题导致json数据传输时间延长
- Erlang 构建多层监督机制
- 安卓学习笔记五
- leetcode - Palindrome Number