This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: Fixing the wrapping issue
On Mon, 15 Aug 2005, Daniel Berlin wrote:
> > Could somebody recall me what is the result of the following conversion:
> >
> > u = (unsigned char) 255;
> > s = (signed char) u;
> >
> > is the signed char conversion defined to be -1 or not defined in this case?
>
> 6.3.1.3 Signed and unsigned integers
> 1 When a value with integer type is converted to another integer type
> other than _Bool,
> the value can be represented by the new type, it is unchanged.
> 2 Otherwise, if the new type is unsigned, the value is converted by
> repeatedly adding
> subtracting one more than the maximum value that can be represented in
> the new
> until the value is in the range of the new type.49)
> 3 Otherwise, the new type is signed and the value cannot be represented
> in it; either
> result is implementation-defined or an implementation-defined signal is
> raised.
>
>
>
> The new type here is signed, so it falls into category 3.
And in implement-c.texi we duly document the definition of such
conversions for GNU C.
--
Joseph S. Myers http://www.srcf.ucam.org/~jsm28/gcc/
jsm@polyomino.org.uk (personal mail)
joseph@codesourcery.com (CodeSourcery mail)
jsm28@gcc.gnu.org (Bugzilla assignments and CCs)