Are user-defined identifiers beginning with a single underscore non-problematic?

coolsubo 注册会员
2023-01-25 20:38

No, there is a problem.

You forgot to include one more quote

So you may not declare an identifier beginning with one underscore followed by an uppercase letter.

In general it is a bad style of programming using identifiers starting with underscore because the reader of the code can think that this identifier is reserved by the implementation.

daiyi0857 注册会员
2023-01-25 20:38

No, that list item merely tells you certain things are problematic. It makes no statement that other things are non-problematic.

The same paragraph tells you that all identifiers listed in the header subclauses are reserved if header that declares them is included, possibly for any use, so they are problematic. There are additional issues listed in that paragraph.

C 2018 5 and 6 tell you that identifiers longer than the minimums listed in (63 characters for internal identifiers, 31 for external) may be a problem; the behavior is not defined if two identifiers differ only beyond the limit of significant characters the implementation imposes.

C 2018 6.4.2 also allows identifiers with implementation-defined characters, so such identifiers may work in some implementations and not others.

dlly2004 注册会员
2023-01-25 20:38

Inside the main function or user defined function, you can write like that

You won't get any compile error.

int main()
 int _var;
 float _var1;
dc346357054 注册会员
2023-01-25 20:38

Yes. As long as:

  • are at block scope (includes enum/struct/union tags)
  • OR are struct/union members
  • OR are function parameters
  • _ is followed by neither capital nor another underscore


struct X { int _a; };
int main() { int _a; }
void foo(int _a);

About the Author

Question Info

Publish Time
2023-01-25 20:38
Update Time
2023-01-25 20:38

Related Question