Re: [dev] Re: Bug in join.c

From: Mattias Andrée <maandree_AT_kth.se>
Date: Mon, 14 Dec 2015 19:23:23 +0100

On Mon, 14 Dec 2015 13:07:48 -0500
Random832 <random832_AT_fastmail.com> wrote:

> Mattias Andrée <maandree_AT_kth.se> writes:
> > I think this patch should be included. But I don't see
> > how it is of substance. It will never occur with two's
> > complement or ones' complement. Only, signed magnitude
> > representatiion. Any sensible C compiler for POSIX
> > systems will only use two's complement; otherwise
> > int[0-9]*_t cannot be implemented.
>
> I had assumed that comparing an unsigned value with a
> negative number resulted in a comparison that is
> unconditionally false, rather than converting one to the
> type of the other. Maybe that's because I've gotten too
> used to non-C languages that don't have fixed-size
> integers.
>
> Sorry for the confusion.
>
>

C is a complicated language, and you always get stuck in
the mind-set for the language you most recently used for
an extended time. At comparison integers are cast to match
each others types. This can see confusing in the case of a
inequality comparison with mixed signs. But, it does not
matter whether the comparands are cast to signed or
unsigned. But `char` is the most confusing of all, it is
always cast to `int`, which makes it very peculiar because
it can either be signed or unsigned, and the result of a
cast depends on the sign. For example (char)255 == -1 may
or may not be true.

Received on Mon Dec 14 2015 - 19:23:23 CET

This archive was generated by hypermail 2.3.0 : Mon Dec 14 2015 - 19:24:23 CET