qsort

Eric W. Sink sink at zorro.cecer.army.mil
Mon Apr 13 15:43:13 EDT 1992


> >Can qsort be used portably?
> We use qsort() in many places n GRASS - it has ported just fine
> to many machines. Go ahead and use it.

There are two working definitions of the word "portable".  Both are
important.

One can view portability the way Michael views it (which is by no
means wrong), in saying that "If a feature or function is available on
a wide variety of machines, it is probably portable."  This definition
tends to work well in practice.

However, it is worthwhile when considering the portability of say, a
library routine, to consider its compliance with a standard, such as
ANSI.  The ANSI standard for the C language specifies not only the
parameters of the language itself, but the functionality of the
standard library functions which accompany a full C platform.  New C
implementations tend to be moving in the ANSI direction.  Viewing the
ANSI standard as totally portable is a rather naive viewpoint for the
time being.  ANSI compliant code SHOULD be portable.  ANSI compliant
code will certainly have a greater chance of being portable in the
future.  However, many existing installations are NOT ANSI compliant.
This is why the more practical viewpoint is needed.  If everyone would
immediately update all their systems to be ANSI compliant, we could
simply program with a copy of Harbison and Steele by our side. (C, A
Reference Manual - 3rd Edition, Prentice Hall - highly recommended).

For the record, qsort() IS in the ANSI standard.  This is an example
of a routine which is portable in more ways than one.

Many routines which we all use commonly are NOT in the ANSI standard.
Usually these routines are in some way dependent on the operating
system (typically UNIX).  For example, fork() is a routine which is
certainly not in the ANSI standard.  The concept of a process fork is
inconceivable in a non-UNIX environment.  Here, we may use yet another
standard, called POSIX.  Just as ANSI C will tell us what SHOULD be
portable because new platforms are following ANSI, POSIX tells us what
SHOULD be portable among UNIX systems.  The fork() routine happens to
be a UNIX routine which works pretty much the same way on almost all
UNIX systems.  I do not have a copy of the draft POSIX standard, but I
am certain that fork() is defined therein.  On UNIX platforms, fork()
is no doubt quite portable.

POSIX is even less mature and universally adopted than the ANSI C
standard.  Don't count on the average installed UNIX system being
POSIX compliant right now, but look around 5 years from now.

Bottom line, if portability is important, look at the issue twice.  Look
once to see if the feature works on lots of platforms.  Look again at
the standards to see if it should work on lots of platforms in the future.

How's that for a 50 line answer to a 1 line question ? :-)

-- 
Eric W. Sink,  Spatial Analysis and Systems Team
USACERL, P.O. Box 9005, Champaign, IL 61826-9005
1-800-USA-CERL x449,   e-sink at uiuc.edu



More information about the grass-dev mailing list