Variable Name Conventions

Henry Spencer henry at utzoo.uucp
Sat Jan 20 05:30:36 AEST 1990


In article <36190 at cornell.UUCP> gordon at cs.cornell.edu (Jeffrey  Adam Gordon) writes:
>I have seen C source with at least three different types of variable
>names.  Some are just 'var' while others are either '_var' or '__var.'
>What I'd like to know is:  is there any convention for using
>underline (and for that matter, CAPS) in C variable/function/structure
>names...

Ignoring some fine points, names with leading underscores are basically 
reserved for use by the implementation.  You use such names for your own
purposes at your peril.  The implementation may make some such names
available to you for specific purposes:  for example, __STDC__ as a
preprocessor macro to test whether you've got an ANSI-standard compiler.

There are various naming schemes for identifiers.  Probably the most
widely used is a vague standard common in Unix sources and among long-time
C programmers:  type names end in _t, macro names are all caps,
ordinary variable names are all lowercase, and there are no particular
stylistic conventions depending on variable type.  There is also the
convention of starting structure member names with xx_, where xx is
an abbreviated version of the structure name, but that's largely an
artifact of now-obsolete namespace structure in early compilers.
-- 
1972: Saturn V #15 flight-ready|     Henry Spencer at U of Toronto Zoology
1990: birds nesting in engines | uunet!attcan!utzoo!henry henry at zoo.toronto.edu



More information about the Comp.lang.c mailing list