Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C++ using C code using double underscores in defines and identifiers

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 );
}

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);

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

like image 223
test Avatar asked Dec 12 '25 10:12

test


2 Answers

In the C++03 standard 17.4.3.1.2 Global names, that use of underscores is defined as reserved:

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.

Being reserved means that it might be used in any conforming implementation and therefore it is not advisable to use it.

like image 199
lccarrasco Avatar answered Dec 14 '25 00:12

lccarrasco


You should be fine, unless by some fluke chance that one of the defines has clashes with your compiler's one. If that is the case, it'll likely be a warning or error (depending on your compiler's configuration) that there'll be a duplicate symbol.

Hope it helps. Cheers!

like image 31
Vern Avatar answered Dec 14 '25 00:12

Vern



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!