c++ 名字粉碎(name mangling)
转自Ibm:
Name mangling is the encoding of function and variable names into unique names so that linkers can separate common names in the language. Type names may also be mangled. The compiler generates function names with an encoding of the types of the function arguments when the module is compiled. Name mangling is commonly used to facilitate the overloading feature and visibility within different scopes. Name mangling also applies to variable names. If a variable is in a namespace, the name of the namespace is mangled into the variable name so that the same variable name can exist in more than one namespace. The C++ compiler also mangles C variable names to identify the namespace in which the C variable resides.
The scheme for producing a mangled name differs with the object model used to compile the source code: the mangled name of an object of a class compiled using one object model will be different from that of an object of the same class compiled using a different object model. The object model is controlled by compiler option or by pragma.
Name mangling is not desirable when linking C modules with libraries or object files compiled with a C++ compiler. To prevent the C++ compiler from mangling the name of a function, you can apply the extern "C" linkage specifier to the declaration or declarations, as shown in the following example:
extern "C" {
int f1(int);
int f2(int);
int f3(int);
};
This declaration tells the compiler that references to the functions f1, f2, and f3 should not be mangled.
The extern "C" linkage specifier can also be used to prevent mangling of functions that are defined in C++ so that they can be called from C. For example,
extern "C" {
void p(int){
/* not mangled */
}
};
http://blog.csdn.net/xt_xiaotian/article/details/5431410
http://www.360doc.com/content/11/0402/17/6295074_106726950.shtml http://www.geeksforgeeks.org/extern-c-in-c/
c++ 名字粉碎(name mangling)的更多相关文章
- 关于extern "C"(详细剖析)
[目录] 引言 extern “C”的前世今生 小心门后的未知世界 Q&A c++调用c的方法 c调用c++的方法 在你工作过的系统里,不知能否看到类似下面的代码. 这好像没有什么问题,你应该 ...
- C++ ABI之名字改变,编译器生成符号研究(以Qt为例)
在C++中,由于重载等技术的存在,编译器要将函数.结构体.类等等的信息传递给链接器,就不能像C语言那样简单地通过函数名来完成,它需要提供额外的参数信息,而还要和C语言共用链接器,这就需要用到名字改编( ...
- C++ ABI之名字改编(以Qt为例)
在C++中,由于重载等技术的存在,编译器要将函数.结构体.类等等的信息传递给链接器,就不能像C语言那样简单地通过函数名来完成,它需要提供额外的参数信息,而还要和C语言共用链接器,这就需要用到名字改编( ...
- C++知识点大汇总
概述 1.1980年 贝尔实验室 Bjanre Stroustrup(比雅尼·斯特劳斯特鲁普)对C改进与扩充 最初称为"带类的C",(c with classes). 1983年正 ...
- 在linux平台实现atosl
➠更多技术干货请戳:听云博客 序言 怎么在linux 平台下实现一个类似于mac 平台下的 atos 工具( iOS 符号化解析)? 分析问题 在github上找到了几年前的开源实现,[https:/ ...
- 动态链接库(VC_Win32)
目录 动态链接库概述相关函数动态链接库编程dumpbin工具 (本章节中例子都是用 VS2005 编译调试的) 动态链接概述 说明 所谓动态链接,就是把一些经常会共用的代码(静态链接的OBJ程序库)制 ...
- C语言可变參函数的实现
1 C语言中函数调用的原理 函数是大多数编程语言都实现的编程要素.调用函数的实现原理就是:运行跳转+參数传递.对于运行跳转,全部的CPU都直接提供跳转指令:对于參数传递,CPU会提供多种方式.最常见的 ...
- C++ 三大特性:封装、继承、多态性
要讲 封装.继承.多态就必须从面向对象说起 开发一个软件是为了解决某些问题,这些问题所涉及的业务范围称为该软件的问题域.面向对象的编程语言将客观事物看作具有属性和行为(或服务)的对象,通过抽象找出同 ...
- C++之继承与多态
在程序设计领域,一个广泛认可的定义是“一种将不同的特殊行为和单个泛化记号相关联的能力”.和纯粹的面向对象程序设计语言不同,C++中的多态有着更广泛的含义.除了常见的通过类继承和虚函数机制生效于运行期的 ...
随机推荐
- 超过2T,磁盘分区
MBR:MBR分区表(即主引导记录)大家都很熟悉.所支持的最大卷:2T,而且对分区有限制:最多4个主分区或3个主分区加一个扩展分区 GPT: GPT(即GUID分区表).是源自EFI标准的一种较新的磁 ...
- HttpWebRequest结合HtmlAgilityPack实现网页form提交
年前一个项目,需要在某个系统实现系统自动操作. 系统页面使用form提交,页面参数较多,也参数设计一系列计算逻辑,改动一个值,其他值自动改变. 传统方法使用正则表达式匹配参数,构建post参数进行请求 ...
- Ionic 弹出窗
Ionic弹窗服务允许程序创建.显示弹出窗口,需要用户继续响应. 弹窗系统支持更多灵活的构建alert(),prompt()和confirm()功能版本,以及用户习惯,除了允许查看完全自定义内容的的弹 ...
- Singleton设计模式 分类: 设计模式 2014-12-03 17:54 59人阅读 评论(0) 收藏
实现方法: public class SingleTon<T> where T : class, new() { protected SingleTon() { } pri ...
- Parse和Convert的区别
DateTime.Parse是转换String为DateTime Convert.ToDateTime是转换继承自Object的对象为DateTime的. 你得到一个object对象,你想把它转换为D ...
- 第一章JSP基础语法
jsp页面元素构成 jsp页面组成部分有:指令,注释,静态内容,表达式,小脚本,声明. jsp指令 page指令:通常位于jsp页面的顶端,同一个页面可以有多个page指令 include指令:将一个 ...
- iOS-assign、copy 、retain等关键字的含义
iOS中assign.copy .retain等关键字的含义 assign: 简单赋值,不更改索引计数 copy: 建立一个索引计数为1的对象,然后释放旧对象 retain:释放旧的对象,将旧对象的值 ...
- CoreAnimation1-图层树、寄宿图以及图层几何学
(一)图层的树状结构 Core Animation其实是一个令人误解的命名.你可能认为它只是用来做动画的,但实际上它是从一个叫做Layer Kit这么一个不怎么和动画有关的名字演变而来,所以做动画这只 ...
- Constant is not finite! That's illegal. constant:inf'
原本使用正常的情况, 切换为测试库突然出现这个错误, 网上搜索并排查后得出导致这个问题的原因: (1)就是你的除数为0(2)除数或者被除数为null 找出你出错的界面, 并打断点, 看看是否出现上面两 ...
- 类库探源——System.String
一.MSDN描述 String 类: 表示文本,即一系列的 Unicode 字符 命名空间 : System 程序集 : mscorlib.dll 继承关系: 备注: 1. 字符串是 Unicode ...