C Variable Naming – Reason for Using Underscore

c++

I am trying to understand when a developer needs to define a C variable with preceding '_'. What is the reason for it?

For example:

uint32_t __xyz_ = 0;

Best Answer

Maybe this helps, from C99, 7.1.3 ("Reserved Identifiers"):

  • All identifiers that begin with an underscore and either an uppercase letter or another underscore are always reserved for any use.

  • All identifiers that begin with an underscore are always reserved for use as identifiers with file scope in both the ordinary and tag name spaces.

Moral: For ordinary user code, it's probably best not to start identifiers with an underscore.

(On a related note, I think you should also stay clear from naming types with a trailing _t, which is reserved for standard types.)