Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c > #164665

Re: C99: 7.18.1.1 Exact-width integer types

From Keith Thompson <Keith.S.Thompson+u@gmail.com>
Newsgroups comp.lang.c
Subject Re: C99: 7.18.1.1 Exact-width integer types
Date 2022-01-26 16:48 -0800
Organization None to speak of
Message-ID <87sftaknqn.fsf@nosuchdomain.example.com> (permalink)
References <86k0emc9ga.fsf@levado.to>

Show all headers | View raw


Meredith Montgomery <mmontgomery@levado.to> writes:
> --8<---------------cut here---------------start------------->8---
> 7.18.1.1 Exact-width integer types
>
> 1. The typedef name intN_t designates a signed integer type with width
> N, no padding bits, and a two's complement representation.  Thus,
> int8_t denotes a signed integer type with a width of exactly 8 bits.
> --8<---------------cut here---------------end--------------->8---
>
> It seems C99 garantees that these nice integers types will use two's
> complement.  But I guess we have no such guarantee for int or char?
> It's only for intN_t.  Can you share your experience on this?  Thank
> you!

The intN_t types are almost certainly, for a given implementation,
defined as typedefs for one of the predefined signed integer types
(signed char, short, int, long, long long).  In almost all existing
implementations, all those types use a 2's-complement representation
with no padding bits.  (The few implementations for non-2's-complement
systems, as far as I know, don't even support C99 and are not likely to
in the future.)

An implementation that uses 1s'-complement or that has padding bits
simply wouldn't define the intN_t types (unless it's able to emulate
the required features).

The predefined types are mandatory, so the standard has to be a bit
flexible about representation to avoid making implementations for exotic
systems impractical.  The intN_t and uintN_t types are optional, and are
defined only if the implementation can support them.

The [u]int_leastN_t and [u]int_fastN_t types do not require
2's-complement, and are mandatory for all conforming implementations for
N = 8, 16, 32, 64.

The next edition of the C standard is likely to mandate 2's-complement
for signed integer types.  Padding bits are still a theoretical issue,
as are sizes other than the usual 8, 16, 32, 64.

-- 
Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com
Working, but not speaking, for Philips
void Void(void) { Void(); } /* The recursive call of the void */

Back to comp.lang.c | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

C99: 7.18.1.1 Exact-width integer types Meredith Montgomery <mmontgomery@levado.to> - 2022-01-26 21:24 -0300
  Re: C99: 7.18.1.1 Exact-width integer types Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2022-01-26 16:48 -0800
    Re: C99: 7.18.1.1 Exact-width integer types Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2022-01-26 17:02 -0800
  Re: C99: 7.18.1.1 Exact-width integer types James Kuyper <jameskuyper@alumni.caltech.edu> - 2022-01-26 21:32 -0500
  Re: C99: 7.18.1.1 Exact-width integer types David Brown <david.brown@hesbynett.no> - 2022-01-27 09:14 +0100

csiph-web