转自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)的更多相关文章

  1. 关于extern "C"(详细剖析)

    [目录] 引言 extern “C”的前世今生 小心门后的未知世界 Q&A c++调用c的方法 c调用c++的方法 在你工作过的系统里,不知能否看到类似下面的代码. 这好像没有什么问题,你应该 ...

  2. C++ ABI之名字改变,编译器生成符号研究(以Qt为例)

    在C++中,由于重载等技术的存在,编译器要将函数.结构体.类等等的信息传递给链接器,就不能像C语言那样简单地通过函数名来完成,它需要提供额外的参数信息,而还要和C语言共用链接器,这就需要用到名字改编( ...

  3. C++ ABI之名字改编(以Qt为例)

    在C++中,由于重载等技术的存在,编译器要将函数.结构体.类等等的信息传递给链接器,就不能像C语言那样简单地通过函数名来完成,它需要提供额外的参数信息,而还要和C语言共用链接器,这就需要用到名字改编( ...

  4. C++知识点大汇总

    概述 1.1980年 贝尔实验室 Bjanre Stroustrup(比雅尼·斯特劳斯特鲁普)对C改进与扩充 最初称为"带类的C",(c with classes). 1983年正 ...

  5. 在linux平台实现atosl

    ➠更多技术干货请戳:听云博客 序言 怎么在linux 平台下实现一个类似于mac 平台下的 atos 工具( iOS 符号化解析)? 分析问题 在github上找到了几年前的开源实现,[https:/ ...

  6. 动态链接库(VC_Win32)

    目录 动态链接库概述相关函数动态链接库编程dumpbin工具 (本章节中例子都是用 VS2005 编译调试的) 动态链接概述 说明 所谓动态链接,就是把一些经常会共用的代码(静态链接的OBJ程序库)制 ...

  7. C语言可变參函数的实现

    1 C语言中函数调用的原理 函数是大多数编程语言都实现的编程要素.调用函数的实现原理就是:运行跳转+參数传递.对于运行跳转,全部的CPU都直接提供跳转指令:对于參数传递,CPU会提供多种方式.最常见的 ...

  8. C++ 三大特性:封装、继承、多态性

    要讲  封装.继承.多态就必须从面向对象说起 开发一个软件是为了解决某些问题,这些问题所涉及的业务范围称为该软件的问题域.面向对象的编程语言将客观事物看作具有属性和行为(或服务)的对象,通过抽象找出同 ...

  9. C++之继承与多态

    在程序设计领域,一个广泛认可的定义是“一种将不同的特殊行为和单个泛化记号相关联的能力”.和纯粹的面向对象程序设计语言不同,C++中的多态有着更广泛的含义.除了常见的通过类继承和虚函数机制生效于运行期的 ...

随机推荐

  1. oracle在敏感操作前创建还原点

    我们都知道,在vmware虚拟机中有一个拍摄快照的功能,我们可以把系统此时的状态保存下来,一方后面遇到不测事件,也好将系统还原,oracle中也有类似功能. 首先创建一张学生表: 向学生表中插入一条数 ...

  2. 15个Linux Yum命令实例--安装/卸载/更新

    在linux环境中, 安装, 卸载更新包是一个极为常见的操作.大部分的linux环境都提供了包的管理工具, 例如:apt-get, dpkg, rpm, yum等等. 一些Linux环境中,yum是默 ...

  3. 为什么要设置Java环境变量(详解)

    关于java环境变量配置讲解: 1. PATH环境变量.作用是指定命令搜索路径,在shell下面执行命令时,它会到PATH变量所指定的路径中查找看是否能找到相应的命令程序.我们需要把 jdk安装目录下 ...

  4. CI框架篇之类库篇--基础(1)

    使用 CodeIgniter 类库: 所有的类库文件存放在system/libraries 文件夹.大多数情况下你需要预先在controller中初始化后才能使用它们: $this->load- ...

  5. (转)Asp.net的HttpCookie写入汉字读取时为乱...

    今天有个问我:在Asp.net的HttpCookie中写入汉字,读取值为什么全是乱码?其实这是因为文字编码而造成的,汉字是两个编码,所以才会搞出这么个乱码出来!其实解决的方法很简单:只要在写入Cook ...

  6. [IO] C# INI文件读写类与源码下载 (转载)

    /// <summary> /// 类说明:INI文件读写类. /// 编 码 人:苏飞 /// 联系方式:361983679 /// 更新网站:[url]http://www.sufei ...

  7. Socket服务器整体架构概述

    转载:http://www.cnblogs.com/tianzhiliang/archive/2010/10/28/1863684.html Socket服务器主要用于提供高效.稳定的数据处理.消息转 ...

  8. C语言malloc()函数:动态分配内存空间

    头文件:#include <stdlib.h> malloc() 函数用来动态地分配内存空间(如果你不了解动态内存分配,请查看:C语言动态内存分配及变量存储类别),其原型为:void* m ...

  9. async: false的应用.

    目的: 手机webview中, js ajax请求, success后, 进行window.open 操作 问题: 在Android, IOS均不能执行window.open 解决办法: 设置ajax ...

  10. 让QMainWindow也表现出QDialog的exec函数的特征

    前几天在做毕业设计项目的时候,使用的PyQt4,想实现这么样一个功能: 场景描述:主窗口a(QMainWindow类型)和主窗口b(QMainWindow),b是通过a窗口中某一个按钮弹出来的. 功能 ...