下划线 [英] Underscores

查看:101
本文介绍了下划线的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


在C语言函数中,编译时会在其名称前面加上下划线。


是他们的编译器/关闭内部下划线的链接器选项


干杯


Terry

解决方案

< blockquote>

不,这是C调用约定的一部分,请参阅
装饰名称
以获取更多信息。


装饰名称有一个非常重要的原因,那就是停止任何自动链接具有不兼容的调用约定的名称。


你问这个问题这个事实让我想知道你是不是在做一些令人讨厌的事情,因为这个问题的唯一重要时刻就是如果你正在使用不同的语言或不同的C / C ++编译器。


这很重要,因为:



  • 不同的语言不能使用任何语言C呼叫惯例
  • 程序集与语言无关,因此您必须遵循调用约定来调用这些函数
  • 不同的C / C ++编译器可能对C调用约定的含义有不同的看法

因此,如果链接不起作用,那么最好的结果将是彻底崩溃,但如果存在堆栈对齐差异或结构返回方式的差异,那么您的应用程序可以继续运行有一些很难跟踪错误。


另外,如果你设法做到这一点,那么你有另一个错误来源,32位编译器支持至少5个调用约定,所以如果你不小心调用标准调用函数(Windows API使用的),当它期望它是一个C调用
函数?


Hi,

In C language functions when compiled get an underscore in front of their names.

Is their a compiler/linker option that turns internal underscores off

Cheers

Terry

解决方案

No, this is a part of the C calling convention, see the documentation on Decorated Names for more information.

The name decoration is there for one very important reason, and that is to stop any automatic linking of names that have incompatible calling conventions.

The fact that you are asking this question makes me wonder if you are doing something nasty, since the only times this would matter is if you are using different languages or different C/C++ compilers.

This matters because:

  • A different language may not use any of the C calling conventions
  • Assembly is language agnostic, so you would have to follow the calling convention to call those functions
  • Different C/C++ compilers may have different ideas about what the C calling convention may mean

So if linking doesn't work then the best result would be an outright crash, but if there is a stack alignment difference or differences in how structures are returned, then your application can keep running with some really hard to track bugs.

Also, if you manage to do this, then you have another source of errors, the 32 bit compiler supports at least 5 calling conventions, so what if you accidentally call an standard call function (which the Windows API uses) when expecting it to be a C call function?


这篇关于下划线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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