Home >Backend Development >C++ >Why Should I Avoid Double Underscores in My C Code?
Double Underscore Usage in C : A Caveat
In C open-source code, one may encounter frequent usage of double underscores (__), particularly in the beginning of variables. This practice has sparked confusion among developers, leading to questions about its purpose.
Reason for Double Underscore (__) Usage
The C standard reserves the use of double underscores (__) in identifiers for the compiler's internal use. Avoiding their use in custom identifiers helps prevent conflicts with the compiler's reserved names.
Underscore Usage in Library Functions
While double underscores are reserved for compiler usage, a single underscore (_) is commonly employed in names of library functions, such as _main and _exit. To prevent name collisions, it is best to refrain from initiating identifiers with an underscore.
Code Readability Concerns
While double underscores serve a specific purpose, they can indeed detract from code readability. They can be easily confused with single underscores, and their presence can clutter the code, potentially hindering understanding.
In summary, double underscores in C are reserved for compiler-specific use, while single underscores are commonly found in library function names. It is advisable to avoid using underscores at the beginning of custom identifiers to prevent conflicts and to enhance code clarity.
The above is the detailed content of Why Should I Avoid Double Underscores in My C Code?. For more information, please follow other related articles on the PHP Chinese website!