转自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. Hibernate 配置派生属性

    在持久化类中,有些属性在表中没有对应的字段,可以在映射文件中设置派生属性. 比如在一个订单中有多个商品的价格,但没有计算总的价格,可以在持久化类中增添一个统计总价格的属性,在映射文件中配置一些信息. ...

  2. Java基础知识强化之集合框架笔记64:Map集合之ArrayList嵌套HashMap

    1. ArrayList集合嵌套HashMap集合并遍历.  需求:         假设ArrayList集合的元素是HashMap.有3个.         每一个HashMap集合的键和值都是字 ...

  3. Windows2012中安装PHP-5.6.20+Apache httpd2.4.18+Composer+Laravel+MySQL5.7

    下载软件包 PHP:  http://windows.php.net/downloads/releases/php-5.6.20-Win32-VC11-x64.zip Apache httpd:  h ...

  4. Linux下安装GAMS建模优化工具

    1.下载GAMS wget http://d37drm4t2jghv5.cloudfront.net/distributions/24.5.6/linux/linux_x64_64_sfx.exe 2 ...

  5. 苹果手机 iframe 无法滚动bug

    原来在html5下,iframe 只有 src 属性scroling='no' 解决办法:在iframe外加一层第div,设置样式-webkit-overflow-scrolling:touch;ov ...

  6. java命名规则

    java变量命名是不能以#开头的.Java变量的命名规则如下:$ .字母.下划线开头都行,不能以数字开头 后面的可以是数字.字母.下划线, 其他的命名方式,都会报错,且不能运行. 以字母.下划线( _ ...

  7. java 反射 - 获取成员变量的值.

    通过反射,可以获取所有声明的成员变量(包括所有的),代码如下: package spt.test.src; public class Person { private String name = &q ...

  8. 3.SQL*Plus命令

    3.1SQL*Plus与数据库的交互 主要用来数据库查询和数据处理的工具. 3.2SQL*Plus运行环境设置 3.2.1SET命令概述 用户可以使用SET命令设置SQL*Plus的运行环境,SET命 ...

  9. 如何把visual studio 2010的工程文件迁入TFS2010中管理

    如何在VS2010里面创建项目并添加到TFS2010里面. 新建一个项目,并把它添加到TFS,我们会收到下面的错误: 这是因为我们没有为项目创建Team project,而把它直接添加到了Team p ...

  10. 输出第N个素数

    输出第N个素数 public class FindNthPrime { public static void main(String[] args){ int N = Integer.parseInt ...