Subject: Re: how to avoid API namespace collisions in an ever evolving system
To: der Mouse <mouse@Rodents.Montreal.QC.CA>
From: Greg A. Woods <>
List: tech-userlevel
Date: 08/13/2002 19:02:07
[ On Tuesday, August 13, 2002 at 23:34:36 (+0200), der Mouse wrote: ]
> Subject: Re: CVS commit: basesrc
> > Nobody forces a programmer to compile _all_ modules in a given
> > program with -D_POSIX_SOURCE.   :-)
> Nobody forces a programmer to use "heapsort" (or any of the many other
> examples you can find scattered throughout /usr/include), either.
> Because a workaround exists does not mean there's no problem.

"-D_POSIX_SOURCE" and the like are not "work arounds" -- they are
standard ways to guarantee that only certain well defined symbol names
provided by the system will be visible to a given program module.  If
you don't want to encounter namespace collisions when you move your code
to another platform (or you move your platform underneath your code),
then these tools are one of the best, and most widely accepted and
implemented, ways of making that happen.  Define the symbol that says
your code expects just annd only a standard environment, then make sure
you don't use any of the symbols provided by the standard environment
(or reserved for its internal but global use).  Voila -- complete
avoidance of namespace collisions forever more, at least for the modules
where you define the protector symobl.

My point was that you don't have to use -D_POSIX_SOURCE for _every_
module in your program.  Thus you can protect the majority of your code
from namespace pollution on any given target platform, and only expose
one or a very few small system dependent modules to such issues, all the
while benefiting from a reasonably stable and minimally capable system
interface in all your code (i.e. you don't have to hide all your code
from the evil system dependent namespace and build private wrappers for
all system interfaces -- just the non-POSIX ones, or whatever).

I.e. -D_POSIX_SOURCE isn't a work-around -- it's the most widely
accepted and implemented solution to this problem.  POSIX isn't the joy
of all system implementors (it's the pain in their neck).  POSIX _is_
the joy of all portable application implementors and maintainers (system
dependent APIs, even the ever evolving ones in new releases of a given
host environment are the pain in the implementor's neck, as you've so
well demonstrated with your "heapsort" example).  Use POSIX for the
majority of your code modules (and specify that you've done so in your
build environment), and you'll only have to deal with non-standard
system-supplied namespace issues when and where you want to use
non-standard system-supplied APIs.

								Greg A. Woods

+1 416 218-0098;            <>;           <>
Planix, Inc. <>; VE3TCP; Secrets of the Weird <>