gpt4 book ai didi

c# - _NAME、__NAME、_NAME_、__NAME__ 等符号的含义

转载 作者:塔克拉玛干 更新时间:2023-11-03 08:24:00 25 4
gpt4 key购买 nike

我在无数 C/C++ 头文件和源文件中看到过这种情况。
除了个人喜好之外,这些不同符号中的每一个的含义是什么?

  • _NAME
  • __NAME
  • _NAME_
  • __NAME__
  • NAME_t

老实说,我唯一理解的是 _NAME,它是一个类的私有(private)成员(至少在 C# 中是这样)。

有人能解释一下它们之间的区别吗?
如果有任何其他值得注意的符号,请提及它们(即使是其他类似的语言)。

谢谢!

最佳答案

___ 开头的名称通常用于保留标识符,您不应定义/创建以该约定开头的标识符。 (_ 后面跟着大写字母)

来自 C99 标准,7.1.3 - “保留标识符”

— 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.

来自 C++03 标准(对 C++98 的修正),第 17.4.3.1.2 节 - “全局名称”

— Each name that contains a double underscore (_ _) or begins with an underscore followed by an upper- case letter (2.11) is reserved to the implementation for any use.

— Each name that begins with an underscore is reserved to the implementation for use as a name in the global namespace

关于c# - _NAME、__NAME、_NAME_、__NAME__ 等符号的含义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4270316/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com