Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 15 Nov 2000 23:27:16 +1100 (EST)
From:      Bruce Evans <bde@zeta.org.au>
To:        David Malone <dwmalone@maths.tcd.ie>
Cc:        "Daniel C. Sobral" <dcs@newsguy.com>, Garance A Drosehn <gad@FreeBSD.org>, cvs-committers@FreeBSD.org, cvs-all@FreeBSD.org
Subject:   Re: cvs commit: src/usr.sbin/lpr/lpd printjob.c
Message-ID:  <Pine.BSF.4.21.0011152253040.4329-100000@besplex.bde.org>
In-Reply-To: <20001115085843.A15581@gosset.maths.tcd.ie>

next in thread | previous in thread | raw e-mail | index | archive | help
On Wed, 15 Nov 2000, David Malone wrote:

> On Wed, Nov 15, 2000 at 06:43:38AM +0900, Daniel C. Sobral wrote:
> 
> > That's true, but, afaik, C standard mandates 2's complement. Also, you
> > forgot 0x01 for sign-bit. :-)
> 
> C99 says that signed types shall be stored as a sign bit, value bits and
> optional padding bits.

It doesn't seem to require the bits to in any particular order or the
groups of bits to be contiguous, except the value bits are required to
have the same semantics as the value bits for the corresponding unsigned
type, so I think they must be contiguous and start at bit 0.

> If the sign bit is zero then the value of the object
> is the same as if it were unsigned. If the sign bit is one then you can
> choose from:
> 
> - sign and magnitude
> - two's complement
> - one's complement
> 
> (unsigned types can also have padding bits).

Note that c99 doesn't say this explicitly.

Garrett said that not even binary is required.  I think this was true for
c89, but c99 implicitly limits the value bits to binary.  c99 adds explicit
definitions for padding bits, including trap bits in padding bits.

Trap bits are relevant to the behaviour of exit(-1).  The kernel converts
the exit code using W_EXITCODE(ret_sig) = ((ret) << 8 | (sig)).  This
gives undefined behaviour, since a bit in (ret) may be shifted to a trap
bit.  In c89, overflow of left shifts of signed types is not explicitly
undefined, but if c89 allows trap bits then the behaviour is implicitly
undefined.  I think c89 is fuzzy enough to allow trap bits.  Some of c89's
fuzziness was fixed in c99.  Overflow of left shifts of signed types is
now explicitly undefined.

Bruce



To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe cvs-all" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?Pine.BSF.4.21.0011152253040.4329-100000>