gnustep-dev
[Top][All Lists]
Advanced

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

Re: scary warning about casts


From: Gregory Casamento
Subject: Re: scary warning about casts
Date: Thu, 2 Dec 2021 19:19:01 -0500


Given that the cast is implicit this is left up to the compiler to determine.  Luckily GCC and clang (our only supported compilers) do this in the way we expect.  I suggest that we do a little better and do the conversion in a more predictable way so that we don't depend on undefined and/or compiler-specific behavior.  GC


On Fri, Nov 26, 2021 at 6:23 AM Riccardo Mottola <riccardo.mottola@libero.it> wrote:
Hello

I noticed I get these warnings, which look a bit scary.

 Compiling file XGServerWindow.m ...
XGServerWindow.m:3960:40: warning: implicit conversion from 'unsigned
int' to 'float' changes value from 4294967295 to
      4294967296 [-Wimplicit-int-float-conversion]
      opacity = (unsigned int)(alpha * 0xffffffffU);
                                     ~ ^~~~~~~~~~~
XGServerWindow.m:3996:31: warning: implicit conversion from 'unsigned
int' to 'float' changes value from 4294967295 to
      4294967296 [-Wimplicit-int-float-conversion]
        alpha = (float)*num / 0xffffffffU;


I think the warning is legit: alpha is float and is multiplied with an
explicit unsigned constant 0xffffffffU.

What is the code trying to achieve here?

Riccardo



--
Gregory Casamento
GNUstep Lead Developer / OLC, Principal Consultant
http://www.gnustep.org - http://heronsperch.blogspot.com
https://www.patreon.com/bePatron?u=352392 - Become a Patron
https://gf.me/u/x8m3sx - My GNUstep GoFundMe

reply via email to

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