函数以下划线开始导致未定义行为的可能性有多大? [英] How likely is a function starting with an underscore to cause undefined behavior?

查看:55
本文介绍了函数以下划线开始导致未定义行为的可能性有多大?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道以下划线或两个下划线开头的函数是由编译器/ c ++保留的
,不应该由用户使用,并且可能是

导致未定义的行为。我的问题是,实际上有多大可能导致
导致未定义的行为?


我问的原因是我正在使用游戏引擎套接字代码在我的计算机上无法正常工作,但似乎在

每个人都可以正常工作。我不是自己编译dll,而是使用相同的一个

,其他人都在使用它。


嗯,引擎的开发者发布了一个.cpp文件

包含套接字代码,我看到他正在使用多个函数

以下划线开头。我已经发布请求他重命名

函数来删除下划线,说明它是保留的。


但是我想知道我是否应该继续查看试图找到

问题的代码,或者如果他重命名函数可能会修复它。不幸的是,我只需要一个来自.dll的文件,所以我不能重新编译它来测试,而且因为

问题在他的机器上不会发生,他无法测试。不是最好的

调试场景肯定。


有没有人经历过由

函数名称引起的任何未定义行为在一两个下划线之前?他的大多数实际上是在前面有2个下划线,例如:

int __get_free_ws_player()

I know that functions starting with an underscore, or two underscores, are
reserved by the compiler/c++ and should not be used by the user and may
cause undefined behavior. My question is, how likely is it to actually
cause undefined behavior?

The reason I''m asking is I''m using a game engine where the sockets code is
not working correctly on my computer, but seems to work correctly on
everyone elses. I am not compiling the dll myself, but using the same one
that everyone else is using.

Well, the developer of the engine has released the one .cpp file that
contains the socket code, and I see he is using a number of functions
preceeded by an underscore. I have posted requesting that he rename the
functions to remove the underscore explaining that it is reserved.

But I want to know if I should keep looking in the code to try to find the
problem, or if him renaming the functions might fix it. Unfortunately, I
only have one file from the .dll so I can''t recompile it to test, and since
the problem doesn''t happen on his machine, he can''t test. Not the best
debugging scenario around for sure.

Has anyone ever experienced any undefined behavior being caused by a
function name being preceeded by an underscore or two? Most of his actually
have 2 underscores in front such as:
int __get_free_ws_player()

推荐答案

Jim Langston写道:
Jim Langston wrote:
我知道以下划线或两个下划线开头的函数由编译器/ c ++保留,不应该由用户使用,并且可能
导致未定义的行为。


实际上,它的标识符以下划线开头,后跟

大写字母,或以两个下划线开头。

我的问题是,实际上导致未定义行为的可能性有多大?


有多大可能?那是不确定的。未定义的一个可能结果是

正是你所期望的。

我问的原因是我正在使用套接字代码的游戏引擎
在我的电脑上无法正常工作,但似乎在每个人都可以正常工作。我不是自己编译dll,而是使用其他人正在使用的同一个。
I know that functions starting with an underscore, or two underscores, are
reserved by the compiler/c++ and should not be used by the user and may
cause undefined behavior.
Actually, it''s identifiers starting with an underscore follwed by an
upper case letter, or starting with two underscores.
My question is, how likely is it to actually
cause undefined behavior?
How likely? That''s undefined. One possible outcome of undefined is
"exactly what you expected".
The reason I''m asking is I''m using a game engine where the sockets code is
not working correctly on my computer, but seems to work correctly on
everyone elses. I am not compiling the dll myself, but using the same one
that everyone else is using.




好​​吧,它可能会这样做你在一个平台上的期望,

并在另一个平台上做一些意想不到的事情。平台通常被认为是使用的编译器和库。我想它可能会在运行时引起问题。这是未定义的。


Ben Pope

-

我不仅仅是一个数字。对很多人来说,我被称为字符串...



Well, it''s possible that it will do what you expected on one platform,
and do something unexpected on another platform. Platform is usually
considered to be the compiler and libraries used. I suppose it''s
possible for it to cause problems at runtime. It is undefined.

Ben Pope
--
I''m not just a number. To many, I''m known as a string...


Ben Pope写道:
Ben Pope wrote:
Jim Langston写道:
Jim Langston wrote:
我知道以下划线或两个下划线开头的函数由编译器/ c ++保留,不应该由用户使用,并且可能导致未定义的行为。
I know that functions starting with an underscore, or two underscores, are
reserved by the compiler/c++ and should not be used by the user and may
cause undefined behavior.



实际上,它的标识符以下划线开头,后面跟着一个大写字母,或者以两个下划线开头。



Actually, it''s identifiers starting with an underscore follwed by an
upper case letter, or starting with two underscores.




严格来说,一个前导下划线后跟一个数字或

小写字母在你自己的命名空间中是合法的(但从不在

全局命名空间或:: std中) :17.4.3.1.2 / 1 [lib.global.names]。

但是,comp.std.c ++新闻组中的文章警告说,某些

编译器操作不正确使用这些标识符用于他们自己的目的。


我的建议是避免使用领先的下划线nam es

完全。它没有为您的代码添加好处,它使您的

代码不那么便携。


一个双输的senerio。



Strictly speaking, a leading underscore followed by a digit or
lower-case letter is legal in your own namespaces (but never in the
global namespace or ::std): 17.4.3.1.2/1 [lib.global.names].
However, articles in the comp.std.c++ newsgroup have warned that some
compilers do improperly use such identifiers for their own purposes.

My advice is to steer clear of using leading underscore names
completely. It doesn''t add benifits to your code, and it makes your
code less portable.

A lose-lose senerio.


2006年3月20日10:18:44 -0800,Axter <去**** @ axter.com>写道:
On 20 Mar 2006 10:18:44 -0800, "Axter" <go****@axter.com> wrote:
然而,comp.std.c ++新闻组中的文章警告说,某些编译器不正确地使用这些标识符用于他们自己的目的。


不正确?那么第17.4.3.1.2节呢?

我的建议是完全避免使用前导下划线名称。它没有为你的代码添加好处,它使你的代码不那么便携。
However, articles in the comp.std.c++ newsgroup have warned that some
compilers do improperly use such identifiers for their own purposes.
Improperly? What about section 17.4.3.1.2?
My advice is to steer clear of using leading underscore names
completely. It doesn''t add benifits to your code, and it makes your
code less portable.




它违反了第17.4.3.1节。 2.


-

Bob Hairgrove
没有********** @ Home.com


这篇关于函数以下划线开始导致未定义行为的可能性有多大?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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