GCC 3.3.1, new warnings with <limits>

Stefan Farfeleder stefan at fafoe.narf.at
Sun Jul 13 11:47:01 PDT 2003

On Sun, Jul 13, 2003 at 01:25:45PM -0500, David Leimbach wrote:
> On Sunday, July 13, 2003, at 1:11PM, M. Warner Losh wrote:
> >In message: <20030713152154.GA96653 at stack.nl>
> >            Jilles Tjoelker <jilles at stack.nl> writes:
> >: The compiler moans about (T)(-1) >= 0 as well. Is the assumption that
> >: (unsigned type)(-1) is never zero valid?
> >
> >yes.  There are no known machines where -1 == 0 for types of different
> >signs.  Further, the C standard says that it must behave as if it is a
> >two's complement machine, and I think that C++ says so too.
> >
> I am pretty certain you can do one's compliment in the C99 standard, 
> and that
> some of that is implementation/platform dependant.


You seem to be confused.  While signed integers certainly can use the
one's complement representation, the conversion of an negative value to
an unsigned type is a different matter.  The relevant quote from C99 is: Signed and unsigned integers

2 Otherwise, if the new type is unsigned, the value is converted by repeatedly adding or
  subtracting one more than the maximum value that can be represented in the new type
  until the value is in the range of the new type.49)

Stefan Farfeleder

More information about the freebsd-current mailing list