什么是C变量名称定义下划线的原因是什么? [英] What is the reason for underscore in C variable name definition?
问题描述
我想,当开发者需要定义一个以precedingç
变量'_'理解。其原因是什么?
例如:
uint32_t的__xyz_ = 0;
也许这会有所帮助,从C99,7.1.3(保留的标识符):
这与下划线和大写字母或其他开头的所有标识符
下划线,始终保留用于任何用途。
这以下划线开头的所有标识符,始终保留用作标识符
在这两个普通和标记的名称空间文件范围。
块引用>道德:对于普通用户code,它可能是最好不要以下划线开头的标识符
(在一个相关的说明,我想你也应该从命名的类型的与被保留用于标准类型的尾随
_t
,留下清晰。)I am trying to understand when a developer needs to define a
C
variable with preceding '_'. What is the reason for it?For example:
uint32_t __xyz_ = 0;
解决方案Maybe this helps, from C99, 7.1.3 ("Reserved Identifiers"):
All identifiers that begin with an underscore and either an uppercase letter or another underscore are always reserved for any use.
All identifiers that begin with an underscore are always reserved for use as identifiers with file scope in both the ordinary and tag name spaces.
Moral: For ordinary user code, it's probably best not to start identifiers with an underscore.
(On a related note, I think you should also stay clear from naming types with a trailing
_t
, which is reserved for standard types.)这篇关于什么是C变量名称定义下划线的原因是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!