使用C代码的C ++在定义和标识符中使用双下划线 [英] C++ using C code using double underscores in defines and identifiers

查看:136
本文介绍了使用C代码的C ++在定义和标识符中使用双下划线的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道在C ++中标识符的双下划线是为编译器保留的.在相应的头文件中,我有一些具有类似于此特征的C代码:

I understand that in C++ double underscores in identifiers are reserved for the compiler. I have some C code which has characteristics similar to this in the corresponding header files:

extern "C" {
    #define HELLO__THERE 1
    int hello__out__there( int );
}

我将在C ++项目中使用此标头,并计划在C ++中执行以下操作:

I will be using this header in a C++ project, and plan to be doing things in C++ like:

if (HELLO__THERE == abc) 
    hello__out__there(foo);

标准涵盖了C ++中的这种可接受的行为吗?

Is this acceptable behavior in C++, covered by the standard?

推荐答案

标识符中的双下划线保留给编译器

double underlines in identifiers are reserved for the compiler

首先,我想是下划线.第二,这样的标识符被保留.那不会阻止不使用它.您可以使用它(直到没有命名冲突为止).

First, it's underscore I guess. Second such identifiers are reserved. That doesn't hold one back to not use it. You can use it (until there is no naming conflict).

标准涵盖了C ++中的这种可接受的行为吗?

Is this acceptable behavior in C++, covered by the standard?

是的.可以接受但是,可接受的代码和好的代码之间是有区别的.如果您遵循正确的编码准则,那么您的代码将是合格的并且可以接受.恕我直言,您应该参考互联网上的一些良好编码标准;它会为您带来很大帮助.

Yes. It's acceptable. However, there is difference between acceptable and good code. If you are following a proper coding guidelines then your code will be good as well as acceptable. IMHO, you should refer to some good coding standards on internet; it will help you a lot.

这篇关于使用C代码的C ++在定义和标识符中使用双下划线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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