如何一个外部" C"申报工作? [英] How does an extern "C" declaration work?

查看:93
本文介绍了如何一个外部" C"申报工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要带一个编程语言课程,我们正在谈论的的externC声明。

I'm taking a programming languages course and we're talking about the extern "C" declaration.

如何在比它连接C和C ++等更深层次的这一声明的工作?这将如何影响所发生的程序以及绑定?

How does this declaration work at a deeper level other than "it interfaces C and C++"? How does this affect the bindings that take place in the program as well?

推荐答案

的externC用来确保下列符号不是的错位(饰)

extern "C" is used to ensure that the symbols following are not mangled (decorated).

示例:

让我们说我们有一个文件名为以下code TEST.CPP

Let's say we have the following code in a file called test.cpp:

extern "C" {
  int foo() {
    return 1;
  }
}

int bar() {
  return 1;
}

如果您运行 GCC -c TEST.CPP -o test.o

在符号名请看下图:

00000010牛逼_Z3barv

00000010 T _Z3barv

00000000牛逼富

00000000 T foo

富()保留其名称。

这篇关于如何一个外部" C"申报工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆