Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 15 Jan 2021 16:26:37 -0800
From:      Mark Millard <marklmi@yahoo.com>
To:        Walter von Entferndt <walter.von.entferndt@posteo.net>
Cc:        freebsd-hackers@freebsd.org
Subject:   Re: Implicit assumptions (was: Re: Some fun with -O2)
Message-ID:  <7AA78AA9-8010-483F-A33B-C50EA17539F1@yahoo.com>
In-Reply-To: <37B00E45-ABCC-4C8D-9BF6-C0DC5142F63A@yahoo.com>
References:  <mailman.29.1610625600.45116.freebsd-hackers@freebsd.org> <8830694.EFs4ROYVHJ@t450s.local.lan> <4E90FC92-D255-4082-9F89-2BEE4D4C4E92@yahoo.com> <5358091.mMMZhaHaU6@t450s.local.lan> <37B00E45-ABCC-4C8D-9BF6-C0DC5142F63A@yahoo.com>

next in thread | previous in thread | raw e-mail | index | archive | help
Walter, you had written:

> Beside that, can you affirm the fix I suggested is correct & portable?

I'm going to suggest some language generality that you
might not want to deal with. N1570 documents such
material, as an example.

Modern C defines that Integer types other than char,
unsigned char, and signed char are made up of:

signed types: value bits, pad bits (zero or more), and a sign bit

unsigned types: value bits, pad bits (zero or more).

There are also things called "trap representations", that
includes pad bits possibly being something like a parity
bit but there will be some other allowed examples listed
below.

(unsigned char only has value bits and signed char has
one sign bit and the rest being value bits. No form of
char has any pad bits. char is like one of the two
that are explicit about signed vs. unsigned.)

In modern C, signed Integers are limited to:

A) two's complement (by far the typical context)
B) sign and magnitude
C) one's complement

For (A) the sign bit being 1 and the rest of the value
bits being 0 is either a trap representation or a normal
value. (Normal value is by far the typical context.)

For (B) the sign bit being 1 and the rest of the value
bits being 0 is either a trap representation or a normal
value. As a normal value, it is the value called "negative
zero".

For (C) the sign bit being 1 and the rest of the value
bits being 1 is either a trap representation or a normal
value. As a normal value, it is the value called "negative
zero".

I'll note that modern C++ has only (A), with zero pad bits
and no trap representations.

You might want to target (A) with zero pad bits and no
trap representations (all bit partterns being normal
values) but still avoiding other undefined behavior and
possibly avoiding implementation-defined behavior.


===
Mark Millard
marklmi at yahoo.com
( dsl-only.net went
away in early 2018-Mar)




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?7AA78AA9-8010-483F-A33B-C50EA17539F1>