Is It Permissible to Use an Underscore in a C Identifier?
C employs certain conventions for naming member variables, such as prefixing them with a character like 'm_' to differentiate them from local variables and parameters. However, the use of underscores as a prefix, as seen in other frameworks like .NET, raises questions about its validity in the C standard.
The Rules Governing Underscore Usage
According to the C standard, the following rules apply to the use of underscores in identifiers:
Reserved Scopes
Global Namespace
std Namespace
C99 Restrictions
While not directly applicable to C , the C99 standard further restricts the use of underscores:
Other Restrictions
POSIX Standard Reserved Identifiers
The POSIX standard also reserves numerous identifiers that may conflict with normal code usage, including those starting with prefixes like "E," "is," "to," and "LC_."
Conclusion
While using underscores in C identifiers is technically allowed, adhering to the rules outlined above is recommended to avoid potential conflicts and confusion.
The above is the detailed content of Can I Use Underscores in C Identifiers Without Breaking the Standard?. For more information, please follow other related articles on the PHP Chinese website!