This is the mail archive of the
mailing list for the GCC project.
Re: Warning for converting (possibly) negative float/double to unsigned int
- From: Manuel LÃpez-IbÃÃez <lopezibanez at gmail dot com>
- To: Bradley Lucier <lucier at math dot purdue dot edu>, gcc at gcc dot gnu dot org
- Date: Sat, 27 Feb 2016 15:01:24 +0000
- Subject: Re: Warning for converting (possibly) negative float/double to unsigned int
- Authentication-results: sourceware.org; auth=none
- References: <56D0C36A dot 5060303 at math dot purdue dot edu>
On 02/26/2016 09:28 PM, Bradley Lucier wrote:
Perhaps this question is appropriate for the gcc mail list.
Converting a float/double to unsigned int is undefined if the result would be
negative when converted to a signed int.
x86-64 and arm treat this condition differently---x86-64 returns a value whose
bit pattern is the same as the bit pattern for converting to signed int, and
arm returns zero. So it would be nice to have a warning that this will (or
I couldn't find such a warning in the GCC manual or in the GCC code base.
prog.cc:4:23: warning: overflow in implicit constant conversion [-Woverflow]
unsigned int z = -2.0;
prog.cc:5:12: warning: conversion to 'unsigned int' from 'double' may alter its
Both warnings exist since quite a long time (10 years?), the latter under the
more general -Wconversion: