[vorbis-dev] More on getopt/getopt_long

Jeff Squyres jsquyres at lsc.nd.edu
Sat Dec 30 15:51:11 PST 2000



getopt() seems to be on all the Unix flavors that I can check (Solaris,
IRIX, AIX, HP-UX, Linux).  getopt() may be a standardized POSIX
function...?  I'm not sure offhand.  Regardless, I think it's safe to
assume that it's in all flavors of Unix -- oggenc/ogg123 need not include
a local version of it for POSIX builds.

Indeed, the getopt.c that is in oggenc is not friendly to the Sun C++
compiler -- it complains about the pre-ANSI prototypes, and the included
getopt.h forces the prototype of getopt() to be:

        int getopt();

which, in C++, is a no-no, because a C function cannot have name
overloading (i.e., when getopt() is declared in getopt.c, it has
arguments, but the prototype in getopt.h doesn't have arguments).  And to
make matters worse, since Solaris has getopt() in libc, it has its own
prototype for getopt() in <stdlib.h>, which conflicts with the one in the
local getopt.h.

The same kinds of issues will arise in IRIX, AIX, and HP-UX with their
respective C++ compilers.  The details will likely be different, but the
issues will essentially be the same.

Can we ditch the getopt() out of oggenc, at least for POSIX builds?
While technically there is no harm with a local version of getopt() with a
C program, it does not seem to be the Right Thing, and can cause a C++
compiler to choke (ok, yes, I'm showing my bias here of stealing oggenc C
code for inclusion in a C++ project).

-----

getopt_long(), however, only appears to be in Linux.  Hence, I think the
real issues for oggenc/ogg123 are:

1. Check if there is <getopt.h>, and conditionally #include either the
   local version (rename it to local_getopt.h or something) or the
   OS/compiler version (<getopt.h>)
2. Check whether there is a getopt_long() defined by the OS/compiler, and
   conditionally compile the local copy if it is not

It would seem correct to separate out getopt_long() and its necessary
support functions into standalone .c/.h files, and only compile them if
the OS/compiler does not already have getopt_long() (use AM_CONDITIONAL
here).

{+} Jeff Squyres
{+} squyres at cse.nd.edu
{+} Perpetual Obsessive Notre Dame Student Craving Utter Madness
{+} "I came to ND for 4 years and ended up staying for a decade"

--- >8 ----
List archives:  http://www.xiph.org/archives/
Ogg project homepage: http://www.xiph.org/ogg/
To unsubscribe from this list, send a message to 'vorbis-dev-request at xiph.org'
containing only the word 'unsubscribe' in the body.  No subject is needed.
Unsubscribe messages sent to the list will be ignored/filtered.



More information about the Vorbis-dev mailing list