您的位置:首页 > 健康 > 美食 > 大连百度推广代理商_公司网站免费建设_中国十大网络营销平台_外贸网站制作推广

大连百度推广代理商_公司网站免费建设_中国十大网络营销平台_外贸网站制作推广

2025/4/17 16:39:20 来源:https://blog.csdn.net/baiyu33/article/details/147181172  浏览:    关键词:大连百度推广代理商_公司网站免费建设_中国十大网络营销平台_外贸网站制作推广
大连百度推广代理商_公司网站免费建设_中国十大网络营销平台_外贸网站制作推广

1. 基础知识

最基本的要求: 字母、数字、下划线组成, 并且不能是数字开头。

禁忌1: C++ 关键字不能用做标识符。 它们是:

alignas alignof asm auto
bool break
case catch char char16_t char32_t class const constexpr const_cast continue
decltype default delete do double dynamic_cast
else enum explicit export extern
false float for friend
goto
if inline int long mutable
namespace new noexcept nullptr
operator
private protected public
register reinterpret_cast return
short signed sizeof static static_assert static_cast struct switch
template this thread_local throw true try typedef typeid typename
union unsigned using
virtual void volatile
wchar_t while

禁忌2:不能包含两个连续的下划线。

禁忌3:不能以下划线 + 大写字母开头。

禁忌4:函数外面定义的标识符, 不能以下划线开头。

禁忌5:宏定义也是 identifier,也需要遵循前面提到的要求: https://en.cppreference.com/w/cpp/preprocessor/replace

禁忌6:和已有宏定义同名, 例如 #include <windows.h> 后, 默认会引入 small/min/max 等宏定义, 会导致无法使用它们作为变量名字(编译报错).

2. 规则太多,记不住?

用 clang 编译器。 指定 -Werror=reserved-identifier 编译选项。

给一个富含各种 reserved identifier 的内容

#define _ENABLE_TEST 1int _Count;int _monster;int main()
{int hello__world;int _Kali;int _yes;return 0;
}

这份代码中只有 _yes 是合法 identifier, 其他都和 reserved identifier 冲突了。

编译:检测到了每一处非法的identifier 命名

g++ test39.cpp -std=c++11 -Werror=reserved-identifier

在这里插入图片描述

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com