Home >Backend Development >C++ >Why Are Double Underscores (__) So Common in C Code?
Double underscores in C code, primarily at the start of variable names, have garnered attention. While it may appear as a matter of style, there is an underlying reason for their frequent usage.
According to the ANSI-C standard, double underscores are reserved for the compiler's internal use. This means that identifiers beginning with __ are typically associated with compiler-defined functions or operations. Using such identifiers in user code could lead to conflicts with the compiler's implementation.
Furthermore, the use of a single underscore (_) at the beginning of variable names is often used in library functions, such as "_main" or "_exit." To avoid collision with these functions, it is generally advised against starting user-defined identifiers with an underscore.
Therefore, the prevalence of double underscores in C code is a measure to avoid naming conflicts with both the compiler's internal functions and established library conventions. It serves as a reminder that, while readability is important, it should not come at the expense of adhering to established coding standards.
The above is the detailed content of Why Are Double Underscores (__) So Common in C Code?. For more information, please follow other related articles on the PHP Chinese website!