下划线名称 [英] underscore names

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

问题描述

我遇到了一些像__gc_context这样的变量名。

我开始考虑一下我是否应该告诉作者这个代码名称

以下划线开头是保留的实施。我决定不要这么做,因为它会让我看起来像是浪费其他人的时间而不是找到真正的错误。

来吧,我们应该采取这个规则有多严重?这不会是一个问题

解决方案

ok写道:

我遇到了一些变量名,如__gc_context 。
我开始考虑一下,如果我应该告诉作者该代码那些以下划线开头的名称是为实现保留的。我决定不这样做,因为它会让我看起来像是那些只是浪费别人的时间而不是找到真正的错误的人。
来吧,我们应该采取这个规则有多严重?


非常严重(ly)!

这不是问题




它是那是一个很大的问题。 C& V 7.1.3p1:


每个标题声明或定义其相关的

子条款中列出的所有标识符,以及可选的声明或者说明在其

相关的未来图书馆指南中列出的子条款和标识符

始终保留用于任何用途或者用作范围标识符。


a ??所有以下划线开头的标识符或者大写的

字母或其他下划线总是保留用于任何用途。

a ??以下划线开头的所有标识符始终保留为

用作标识符,其中包含普通和标记名称的范围

空格。


PS

你确定你没有拖钓吗?


-

BR,弗拉基米尔


你肯定打算很快开始生活。


> ;我开始考虑一下,如果我应该告诉作者那个名称

以下划线开头的代码是为实现保留的。




I认为关于名称的约定说明以

下划线开头的名字以及第一个非下划线字母大写的名称是为实现C库而保留的。
。我看到了PJ Plauger在他的书STD C Library中提出的建议




特别是我避免使用下划线命名变量作为第一个

字符,因为我在过去使用Tru64 C库时遇到了问题

实现。但是我不确定你是否应该担心它。一个

很多人使用下划线开始他们认为的名称内部

并且不打算出口。





ok写于03/01/06 13:13,:

我遇到了一些变量名,如__gc_context。
我开始考虑一下,如果我应该告诉作者那个代码名称
以下划线开头是为实现保留的。我决定不这样做,因为它会让我看起来像是浪费别人的时间,而不是找到真正的错误。
来吧,我们应该采取这个规则有多严重?这不会是一个问题




你是*所以*对!和学生一起打倒!但是为了感兴趣,你会在你的系统上尝试以下

程序并告诉我们输出是什么吗?


#include< assert.h>

#include< ctype.h>

#include< errno.h>

#include< float.h>

#include< inttypes.h>

#include< iso646.h>

#include< limits.h>

#include< locale.h>

#include< math.h>

#include < setjmp.h>

#include< signal.h>

#include< stdarg.h>

#include< stddef.h>

#include< stdio.h>

#include< stdlib.h>

#include< string。 h>

#include< time.h>

#include< wchar.h>

#include< wctype.h>


int __EXTENSIONS__ = __LINE __;

int __MATHERR_ERRNO_DONTCARE = __LINE __;

int __P = __LINE __;

int __PRAG MA_REDEFINE_EXTNAME = __LINE __;

int ___errno = __LINE __;

int __assert = __LINE __;

int __buf = __LINE __;

int __filbuf = __LINE __;

int __flsbuf = __LINE __;

int __flt_rounds = __LINE __;

int __fltrounds = __LINE __;

int __i386 = __LINE __;

int __ia64 = __LINE __;

int __lint = __LINE __;

int __longlong_t = __LINE __;

int __posix_asctime_r = __LINE __;

int __posix_ctime_r = __LINE __;

int __posix_sigwait = __LINE __;

int __setp = __LINE __;

int __sigev_pad2 = __LINE __;

int __signo = __LINE __;

int __sparc = __LINE __;

int __strptime_dontzero = __LINE__ ;

int __time = __LINE __;

int __tm = __LINE __;

int __va_list = __LINE __;


#define SHOW(x)printf("%s ==%d \ n",STRING(x),x);


int main(void)

{

SHO W(__ EXTENSIONS__);

SHOW(__ MATHERR_ERRNO_DONTCARE);

SHOW(__ P);

SHOW(__ PRAGMA_REDEFINE_EXTNAME);

SHOW(___ errno);

SHOW(__断言);

SHOW(__ buf);

SHOW(__ filbuf);

SHOW(__ flsbuf);

SHOW(__ flt_rounds);

SHOW(__ fltrounds);

SHOW(__ i386);

SHOW(__ ia64);

SHOW(__ lint);

SHOW(__ longlong_t);

SHOW(__ posix_asctime_r);

SHOW(__ posix_ctime_r);

SHOW(__ posix_sigwait);

SHOW(__ setp);

SHOW(__ sigev_pad2 );

SHOW(__ signo);

SHOW(__ sparc);

SHOW(__ strptime_dontzero);

SHOW (__time);

SHOW(__ tm);

SHOW(__ va_list);

返回0;

}

-
Er ********* @ sun。 com


I came across some variable name like __gc_context.
I started thinking a bit if I should tell the author of that code that names
starting with underscores are reserved for the implementation. I decided not
to because it would make me look like somebody who just wastes other
people''s time instead of finding real bugs.
Come on, how serious should we take this rule? This wont ever be an issue

解决方案

ok wrote:

I came across some variable name like __gc_context.
I started thinking a bit if I should tell the author of that code that
names starting with underscores are reserved for the implementation. I
decided not to because it would make me look like somebody who just
wastes other people''s time instead of finding real bugs.
Come on, how serious should we take this rule?
Very serious(ly)!
This wont ever be an issue



It is, and a big one at that. C&V 7.1.3p1:

Each header declares or de???nes all identi???ers listed in its associated
subclause, and optionally declares or de???nes identi???ers listed in its
associated future library directions subclause and identi???ers which are
always reserved either for any use or for use as ???le scope identi???ers.

a?? All identi???ers that begin with an underscore and either an uppercase
letter or another underscore are always reserved for any use.
a?? All identi???ers that begin with an underscore are always reserved for
use as identi???ers with ???le scope in both the ordinary and tag name
spaces.

PS
Are you sure you''re not trolling?

--
BR, Vladimir

You definitely intend to start living sometime soon.


> I started thinking a bit if I should tell the author of that code that names

starting with underscores are reserved for the implementation.



I think that the convention about names says that names starting with
underscores and with the first non-underscore letter capitalized are
reserved for the implementation of the C library. I saw a suggestion
made by P.J. Plauger on his book "STD C Library".

Particularly I avoid naming variables with underscores as first
characters because I had problems in the past with Tru64 C library
implementation. However I''m not sure if you should worry about it. A
lot of people use underscores to start names they consider "internal"
and are not intended to be exported.




ok wrote On 03/01/06 13:13,:

I came across some variable name like __gc_context.
I started thinking a bit if I should tell the author of that code that names
starting with underscores are reserved for the implementation. I decided not
to because it would make me look like somebody who just wastes other
people''s time instead of finding real bugs.
Come on, how serious should we take this rule? This wont ever be an issue



You are *so* right! Down with the pedants! Just for
the sake of interest, though, would you try the following
program on your system and tell us what the output is?

#include <assert.h>
#include <ctype.h>
#include <errno.h>
#include <float.h>
#include <inttypes.h>
#include <iso646.h>
#include <limits.h>
#include <locale.h>
#include <math.h>
#include <setjmp.h>
#include <signal.h>
#include <stdarg.h>
#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <wchar.h>
#include <wctype.h>

int __EXTENSIONS__ = __LINE__;
int __MATHERR_ERRNO_DONTCARE = __LINE__;
int __P = __LINE__;
int __PRAGMA_REDEFINE_EXTNAME = __LINE__;
int ___errno = __LINE__;
int __assert = __LINE__;
int __buf = __LINE__;
int __filbuf = __LINE__;
int __flsbuf = __LINE__;
int __flt_rounds = __LINE__;
int __fltrounds = __LINE__;
int __i386 = __LINE__;
int __ia64 = __LINE__;
int __lint = __LINE__;
int __longlong_t = __LINE__;
int __posix_asctime_r = __LINE__;
int __posix_ctime_r = __LINE__;
int __posix_sigwait = __LINE__;
int __setp = __LINE__;
int __sigev_pad2 = __LINE__;
int __signo = __LINE__;
int __sparc = __LINE__;
int __strptime_dontzero = __LINE__;
int __time = __LINE__;
int __tm = __LINE__;
int __va_list = __LINE__;

#define SHOW(x) printf("%s == %d\n", STRING(x), x);

int main(void)
{
SHOW(__EXTENSIONS__);
SHOW(__MATHERR_ERRNO_DONTCARE);
SHOW(__P);
SHOW(__PRAGMA_REDEFINE_EXTNAME);
SHOW(___errno);
SHOW(__assert);
SHOW(__buf);
SHOW(__filbuf);
SHOW(__flsbuf);
SHOW(__flt_rounds);
SHOW(__fltrounds);
SHOW(__i386);
SHOW(__ia64);
SHOW(__lint);
SHOW(__longlong_t);
SHOW(__posix_asctime_r);
SHOW(__posix_ctime_r);
SHOW(__posix_sigwait);
SHOW(__setp);
SHOW(__sigev_pad2);
SHOW(__signo);
SHOW(__sparc);
SHOW(__strptime_dontzero);
SHOW(__time);
SHOW(__tm);
SHOW(__va_list);
return 0;
}
--
Er*********@sun.com


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

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