I'm new to C++ and the project in which I'm working contains many header files which contain some macros in the beginning (particularly for defining the size of the array variables along with the header guards). The macros contain underscores and double underscores in the beginning and end, whose use seem random to me. Is this acceptable or something to be avoided.
Asked
Active
Viewed 13 times
0
-
But I couldn't understand much over there. – Vishal Sharma Nov 09 '17 at 08:39
-
It should be avoided. Names beginning with an underscore and a capital letter, or two underscores, are reserved and should not be used. It doesn't mean that something will break, it means that something *might* break. Usually it's fine, but it's bad style. – Nikos C. Nov 09 '17 at 09:53
-
1@NikosC. — names **containing** two consecutive underscores are reserved, not just names beginning with two underscores. – Pete Becker Nov 09 '17 at 14:25
-
By convention, macros defined in the program source code **should** be all UPPERCASE to avoid conflicting with non-macro names, see [Stop the constant SHOUTING!](https://accu.org/index.php/articles/1923) for more rationale. As a requirement of the standard, **all names** defined in the program source code **must not** begin with an underscore followed by an uppercase letter, and **must not** contain two consecutive underscores anywhere (including at the beginning or end). Compilers will not enforce these rules, so it's your code's responsibility to get it right. – Jonathan Wakely Feb 04 '19 at 11:11