Re: Strange conversion to int64

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

 



On 28 January 2010 12:55, Tony Bernardin <sarusama@xxxxxxxxx> wrote:
>
> ok, I understand now how 4294967295 is generated in that first case.
> Am I understanding right that in the other case at line 18, it works
> out "right" because there is no zero-extension and the coercion to a
> signed type will interpret the bits "properly"?
>

In that one it's int32 * uint64, so the (int32)-1 gets promoted to
int64, which uses sign-extension, so you get (int64)-1.  That then
gets reinterpreted as uint64, giving 0xFFFFFFFFFFFFFFFF, but
multiplication in twos-complement is the same as unsigned
multiplication, so the result just so happens to work out to the value
you want.

As others have said, I suggest trying on all the warnings you can
(-Wsign-conversion in particular, iirc) and being explicit about all
such conversions so you're sure what you'll get.

~ Scott

[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux