Strange conversion to int64

Mon Feb 1 20:57:00 GMT 2010

On 28 January 2010 12:55, Tony Bernardin <> 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

More information about the Gcc-help mailing list