What are the rules about using an underscore in a C++ identifier?

C++Server Side ProgrammingProgramming

From MSDN docs −

Use of two sequential underscore characters ( __ ) at the beginning of an identifier, or a single leading underscore followed by a capital letter, is reserved for C++ implementations in all scopes. You should avoid using one leading underscore followed by a lowercase letter for names with file scope because of possible conflicts with current or future reserved identifiers.

So you should avoid using names like −

__foo, __FOO, _FOO

And names like the following should not be used in the global namespace −

_foo, _bar

Other than this, there are some more prefixes like LC_, SIG_, and suffixes like _t should not be used as they're also reserved for the implementation.

So you can create variables that contain the underscore between the name or ends with an underscore.


raja
Published on 28-Feb-2018 06:14:09
Advertisements