help-gengetopt
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [help-gengetopt] options with values and enum type


From: J. David Bryan
Subject: Re: [help-gengetopt] options with values and enum type
Date: Tue, 30 Oct 2007 16:51:19 -0400

On 26 Oct 2007 at 18:51, Lorenzo Bettini wrote:

> actually, the implementation was quite easy, but it relies on enums 
> being treated as int; does any of you know whether this is safe?

The C99 Standard (ISO 9899) says that it is:

   6.7.2.2 Enumeration specifiers

   The identifiers in an enumerator list are declared as constants that
   have type int and may appear wherever such are permitted.

   [...]

   Each enumerated type shall be compatible with char, a signed integer
   type, or an unsigned integer type. The choice of type is
   implementation-defined....


> Basically, when assigning the argument to such an option, I actually
> assign it the index of the value found in the array of strings
> containing the accepted values; this relies on the fact that the first
> enum value is always 0. 

That should be fine.


> I hope to get some feedback soon

I'll test it out with the programs that prompted by original post and 
report back.

Thanks for the updates!

                                      -- Dave





reply via email to

[Prev in Thread] Current Thread [Next in Thread]