kicad-developers team mailing list archive
-
kicad-developers team
-
Mailing list archive
-
Message #22445
Re: [PATCH] Fix out-of-range enum comparison
Chris,
I'm fine with committing this as long as it doesn't break anything which
I don't see why it would.
Thanks,
Wayne
On 1/5/2016 11:11 AM, Chris Pavlina wrote:
> Hi,
>
> layers_id_colors_and_visibility.h defines enum LAYER_ID as unsigned,
> then #defines two negative constants to be used with the enum.
> Comparisons of these generate the following warning:
>
> warning: comparison of constant 4294967295 with expression of type 'int'
> is always true [-Wtautological-constant-out-of-range-compare]
>
>
> Currently there is no problem (I actually dug into the assembler to make
> sure the comparison was being generated). However, this is a time bomb
> just waiting for a different compiler version which decides to optimize
> out what it sees as a tautological comparison, and the fix is very, very
> simple.
>
> Attached patch does two things:
>
> 1) Move the negative constants INTO the enum so that the compiler knows
> to assign the enum a backing type that supports negatives.
>
> 2) Remove the unnecessary forced-typing of the enum. There is absolutely
> no reason this enum has to be an unsigned-char; I suspect this was an
> instance of overzealous and misguided "optimization". This
> "optimization" will at best not do anything (as the compiler will decide
> to pad out the char to the platform's word length anyway), and at worst
> make things even /slower/ (if the compiler actually decides to access it
> as a char).
>
> --
> Chris
>
>
>
> _______________________________________________
> Mailing list: https://launchpad.net/~kicad-developers
> Post to : kicad-developers@xxxxxxxxxxxxxxxxxxx
> Unsubscribe : https://launchpad.net/~kicad-developers
> More help : https://help.launchpad.net/ListHelp
>
References