[PATCH] osmocon: correct parsing of -m

Sylvain Munaut 246tnt at gmail.com
Wed Dec 14 07:03:32 UTC 2011


> That's only certain if one enum value is defined to >= 0, and no
> later enum is defined to < 0. If no enum value is defined at all,
> then they may very well be negative.

Well yes, I was talking about this particular case.


>> And since the enum type in this case is unsigned, an unsigned value
>> can never be inferior to 0 and so the test is always false.
>
> enums don't have signedness AFAIU?

They do (in the underlying type).

But it can be anything the compiler decides as long as it can fit all
the enumeration constant and is no larger than int. And since in this
case there is no negative constant (begin at 0 and go up), the
compiler is free to decide to use "unsigned int" as underlying type.
And gcc does that, yielding a bug in this case.

See the test case posted in IRC yesterday:
http://pastebin.com/raw.php?i=cqi0ipY9

If you compile with -Wextra, you will see the issue.

Cheers,

    Sylvain




More information about the baseband-devel mailing list