Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP
Path: utzoo!mnetor!seismo!rutgers!ames!ucbcad!ucbvax!decvax!tektronix!uw-beaver!tikal!hplsla!bam
From: bam@hplsla.HP.COM
Newsgroups: comp.lang.c
Subject: Re: draft ANSI standard:  one change that would *really* help Europe
Message-ID: <690001@hplsla.HP.COM>
Date: Tue, 16-Dec-86 18:20:12 EST
Article-I.D.: hplsla.690001
Posted: Tue Dec 16 18:20:12 1986
Date-Received: Thu, 18-Dec-86 23:53:38 EST
References: <1382@hoptoad.uucp>
Organization: HP Lake Stevens
Lines: 30

In article <518@brl-sem.ARPA> ron@brl-sem.ARPA (Ron Natalie ) writes:
>> ... nowhere is it stated that (unsigned) -1 will give you a word of
>>all ones.  Becareful when making this assumption.  I spend a lot of time
>>fixing up the Berkeley network code because of this.
>
>	Actually, I think (unsigned) -1 does have to give you a bit pattern of
>all 1's.  I can not find an explicit reason, but I can deduce this from the
>following:
>
>--------
>Kenneth R. Ballou			ARPA:  ballou@brahms
>Department of Mathematics		UUCP:  ...!ucbvax!brahms!ballou
>University of California
>Berkeley, California  94720
>----------

    Try evaluating (unsigned) -1 on a one's complement machine!  A word
containing all ones in such a machine (e.g. CDC Cyber machines) is 
taken to be "negative zero", which is really an illegal representation.

    Using (unsigned) -1 is asking for trouble.  A better approach is
to use the bitwise complement operator '~':

    int allones = ~0;

    This works for any size integer.

    Ben Mejia
    Hewlett-Packard Lake Stevens Instrument Division
    Everett WA