getopt reinvocation/reentrancy

Ralf Corsepius ralf.corsepius@rtems.org
Mon Mar 3 19:05:00 GMT 2008


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_.

- All of these macros are not standardized anywhere nor am I aware about
any system providing them. I vote for removing them.

Ralf



More information about the Newlib mailing list