getopt reinvocation/reentrancy
Gregory Pietsch
gpietsch@comcast.net
Mon Mar 3 20:17:00 GMT 2008
I got the definition of the GETOPT_DATA_INITIALIZER macro from that old
libc manual that Joel provided the link for:
http://sourceware.org/ml/libc-alpha/2004-03/msg00031/libc-manual.diff .
As far as the other #defines, I just think that having non-masking
macros in lowercase looks icky. But that's a matter of style, not substance.
Gregory
Jeff Johnston wrote:
> Ralf Corsepius wrote:
>> On Thu, 2008-02-28 at 19:21 -0500, Gregory Pietsch wrote:
>>
>>> I believe that I caught the problem. In your test program, the -a and -b
>>> switches weren't defined in your list of short options, so getopt was
>>> returning a question mark. Fixing the testing program and applying the
>>> latest Bug-Free(tm) getopt should work. -- Gregory
>>>
>>
>> I think, some defines, you added to getopt.h with your most recent patch
>> should be removed. In particular:
>>
>> /* macros defined by this include file */
>> #define NO_ARG 0
>> #define REQUIRED_ARG 1
>> #define OPTIONAL_ARG 2
>> /* The GETOPT_DATA_INITIALIZER macro is used to initialize a
>> statically-
>> allocated variable of type struct getopt_data. */
>> #define GETOPT_DATA_INITIALIZER {0,0,0,0,0}
>>
>> Rationale:
>>
>> - The *_ARG macros are not name-space safe and likely to clash with
>> other macros. If they really should be kept, then they should be
>> prefixed with __GETOPT_.
>>
>>
> To be fair, the header file itself is non-standard; it is a glibc
> extension and any application that includes it will need the
> non-standard bits (one can get getopt() already through unistd.h).
> The glibc version of <getopt.h> includes 3 macros: no_argument,
> required_argument, optional_argument that are unprotected. The
> sys/linux version of getopt.h defines the 3 glibc macros as well for
> compatibility and so should the libc/include version. I'd be happy
> with only having the glibc names. Joel, as one of probably few
> getopt.h/getopt users, do you think it would be reasonable to make
> this change?
>
> I think that GETOPT_DATA_INITIALIZER should be underscored since it is
> our own invention and is current. I'll do that plus add the glibc macros.
>> - All of these macros are not standardized anywhere nor am I aware about
>> any system providing them. I vote for removing them.
>>
>>
> Glibc extension.
>
> -- Jeff J.
>
More information about the Newlib
mailing list