zoukankan      html  css  js  c++  java
  • 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/
  • 相关阅读:
    将CSV格式的文件导入到数据中
    查询及删除数据重复记录的方法
    创建job
    存储过程动态创建表,以时间给表命名
    索引表空间
    sequence 作为序列插入值不是第一个
    2.类(对象)之间的关系
    1.类和对象
    angularJS1笔记-(1)-多控制器
    angularJS中$apply()方法详解
  • 原文地址:https://www.cnblogs.com/youxin/p/3724430.html
Copyright © 2011-2022 走看看