Date: Fri, 20 Oct 1995 13:13:42 -0700 (MST) From: Terry Lambert <terry@lambert.org> To: twpierce@midway.uchicago.edu (Tim Pierce) Cc: questions@freebsd.org, twpierce@midway.uchicago.edu Subject: Re: POSIX status of getopt(3) Message-ID: <199510202013.NAA05211@phaeton.artisoft.com> In-Reply-To: <CMM.0.90.4.814207196.twpierce@kimbark.uchicago.edu> from "Tim Pierce" at Oct 20, 95 11:39:56 am
next in thread | previous in thread | raw e-mail | index | archive | help
> I'm running 2.0R. (Yes, I know I should upgrade, but at > present my only method of doing so is via floppy disk, and I > have other priorities at the moment.) In stdlib.h, if the > macro _POSIX_SOURCE is defined, then `optarg' and `getopt' > (among other symbols) are not defined or declared: > > #if !defined(_ANSI_SOURCE) && !defined(_POSIX_SOURCE) > ... > extern char *optarg; > extern int opterr, optind, optopt; > int getopt __P((int, char * const *, const char *)); > > Yet the man page for getopt(3) implies that it's acceptable > to use it in a POSIX environment. > > EXTENSIONS > The `optreset' variable was added to make it possible to > call the getopt() function multiple times. This is an > extension to the IEEE Std1003.2 (``POSIX'') > specification. > > Can any of you shed some light on this? Should <stdlib.h> > actually be declaring optarg, optind and the rest? Or if I'm > compiling with _POSIX_SOURCE turned on, should I expect > these to be defined/declared somewhere else? When you define _POSIX_SOURCE, you turn of non-POSIX capabilities. Including so-called "extensions", like getopt(3). The qualifier "extension" means "not part of the standard". If you want "extensions", then you must not define _POSIX_SOURCE. Terry Lambert terry@lambert.org --- Any opinions in this posting are my own and not those of my present or previous employers.
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199510202013.NAA05211>