On Tue, 06 Sep 2011 02:20:31 +0200 Carl-Daniel Hailfinger c-d.hailfinger.devel.2006@gmx.net wrote:
should we also check against < 0? enums are based on int.
Not sure about that: http://software.intel.com/en-us/articles/strict-ansi-switch-in-linux-and-mac... Are they really guaranteed to be signed int? If not, some compilers will warn about "comparison always yields false".
6.7.2.2 Enumeration specifiers paragraph 2: "The expression that defines the value of an enumeration constant shall be an integer constant expression that has a value representable as an int." but that does only restrict the "input" type of the "initializers".
the really important part is paragraph 4: "Each enumerated type shall be compatible with char, a signed integer type, or an unsigned integer type. The choice of type is implementation-defined, but shall be capable of representing the values of all the members of the enumeration. The enumerated type is incomplete until after the } that terminates the list of enumerator declarations."
so eventually this is another implementation-defined behavior, hurray.
gcc does this: http://gcc.gnu.org/onlinedocs/gcc-4.1.1/gcc/Structures-unions-enumerations-a...
define a precondition for programmer_init that parameter prog must be in the range defined by the enum and else the behavior is undefined, and think of the > part of the check as a user-friendly bonus :) a detailed description of what the functions exported by libflashrom do is required anyway...
i am fine with the current implementation.