Upon meandering through source code I noticed a large amount of
preprocessor constants with one or two '_' characters prefixed and
postfixed to them. For example: __SYSCORE__ or __IND86__.
What do the '__' before and after the constant supposed to denote?
Why put them there?
[/QUOTE]
Names starting with two underscores are reserved for the C compiler
builders.
You can't use a variable name in your code with two underscores and
expect it to work on all compilers.
With some exceptions, a more general version of this applies: you
cannot use any identifiers with a leading single underscore followed
by an uppercase letter. (The exceptions include the wretched names
_IOFBF, _IOLBF, and _IONBF that programmers are to supply to the
setbuf() function.)
It might be more interesting to consider, instead of "what" the
precise rules are -- these can be found in the C standard -- "why"
these rules exist.
Most people reading this are probably "programmers writing C
programs". As an individual, or a member of a programming team,
you will need to use various identifiers to name functions, local
variables, external variables, structures, structure members, and
so on. But consider the person or persons writing the C compiler
(including C library) that you are using. If they are writing some
or all of the support code in C, they too need to use various
identifiers to name functions, variables, structures, and so on.
When I wrote 64-bit integer support for 4.xBSD, I used a slightly
modified version of Knuth's "Program D" (vol 2, 2nd ed., section
4.3.1, pp. 257--259) to compute "long long dividend / long long
divisor", giving both a quotient and a remainder. But GCC wants
to call this as __divdi3() for quotient only, and __moddi3() for
remainder only. (Note that the C compiler has already dictated
the form of the names of the support routines, and used these double
underscores.) What should I name my "divide giving both quotient
AND remainder" function so that I can call it from __divdi3 and
__moddi3 as needed?
If I used a name like "qdivrem", I would be taking a name that is
reserved to *you*, the programmer(s) writing programs in C.
Fortunately, I have a name-space reserved to *me* -- the implementor
-- so I can just name the function __qdivrem(), which is what I
did.
If "application programmers" use only "their" names, and "implementation
programmers" keep to theirs, neither group will ever "step on" the
other by mistake.
Note that this leaves "third-party library" writers in a bit of a
bind. If you are writing, say, a new compression library, or
routines to do Fourier transforms, or a matrix library, or any
other reasonably "package-able" set of routines, what names can
*you* use without colliding with either the implementor or the
application programmer? You are stuck -- there is no name space
reserved to you. The best you can do, which actually turns out to
be pretty good (at least in C99 where the annoying "six monocase
characters" restriction is gone), is to pick a prefix in the "user"
(application programmer, "not-implementor") name space, and attach
that to everything you write. An end-user who wants to use your
library can simply avoid using that prefix. If you go with at
least two or three letters, it will probably not be too annoying.