tl; dr You got it backwards. Name your own stuff without leading underscores, unless you're writing a library for someone else. The standard library and compilers use the technique to signal that certain names are internal, and not to be used directly.
Underscores for Uniqueness
In C
, there are no namespaces. In other words, all names included into a file can collide with each other. If foo.h
and bar.h
both define x
, an error will occur when they are both included.
Now, x
is a pretty common name. Collision is almost guaranteed, and the writers of foo.h
and bar.h
must realize that. So, in the interest of avoiding future problems for the programmers that will use their code, they change the name to _x
.
Alternatives
Common names do occur. Before resorting to underscoring, try:
Separating private from public variables in .c
and .h
files. Most clashing names are private, and don't belong in the header.
Prefixing your code with the name of the module: foo_x
and bar_x
won't collide.