为什么人们在 C++ 中如此频繁地使用 __(双下划线) [英] Why do people use __ (double underscore) so much in C++

查看:30
本文介绍了为什么人们在 C++ 中如此频繁地使用 __(双下划线)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我浏览了一些开源 C++ 代码,发现代码中使用了很多双下划线,主要是在变量名的开头.

I was taking a look through some open-source C++ code and I noticed a lot of double underscores used within in the code, mainly at the start of variable names.

return __CYGWIN__;

只是想知道:这是有原因的,还是只是某些人的代码风格?我会认为它很难阅读.

Just wondering: Is there a reason for this, or is it just some people's code styles? I would think that it makes it hard to read.

推荐答案

来自 C++ 编程、规则和建议 :

根据 ANSI-C 标准,标识符中使用两个下划线 (`__') 保留供编译器内部使用.

The use of two underscores (`__') in identifiers is reserved for the compiler's internal use according to the ANSI-C standard.

下划线 (`_') 常用于库函数的名称中(例如_main"和_exit").为避免冲突,标识符不要以下划线开头.

Underscores (`_') are often used in names of library functions (such as "_main" and "_exit"). In order to avoid collisions, do not begin an identifier with an underscore.

这篇关于为什么人们在 C++ 中如此频繁地使用 __(双下划线)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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