C99 stdint.h

  • Thread starter Frederick Gotham
  • Start date
F

Frederick Gotham

Here's an excerpt from the Dinkumware library reference:
__________
| uint8_t, uint16_t, uint32_t, uint64_t
|
| The types each specify an unsigned integer type
| whose representation has exactly eight, 16, 32,
| or 64 bits, respectively.
__________

How could that be possible if we had a 36-Bit system such as the following?

char: 9-Bit
short: 18-Bit
int: 36-Bit
long: 36-Bit
 
R

Richard Heathfield

Frederick Gotham said:
Here's an excerpt from the Dinkumware library reference:
__________
| uint8_t, uint16_t, uint32_t, uint64_t
|
| The types each specify an unsigned integer type
| whose representation has exactly eight, 16, 32,
| or 64 bits, respectively.
__________

How could that be possible if we had a 36-Bit system such as the
following?

char: 9-Bit
short: 18-Bit
int: 36-Bit
long: 36-Bit

Well, it couldn't, obviously. And even if it could, would it matter?
 
F

Frederick Gotham

Richard Heathfield posted:
Frederick Gotham said:


Well, it couldn't, obviously. And even if it could, would it matter?


I would understand if it read:

Where possible, the types "uint8_t, uint16_t, uint32_t, uint64_t"
denote an unsigned integer type whose representation has exactly...

But it doesn't say "where possible" -- it plainly states that these types
are available... ?
 
U

Ulrich Eckhardt

Frederick said:
| uint8_t, uint16_t, uint32_t, uint64_t [...]
How could that be possible if we had a 36-Bit system such as the
following?

char: 9-Bit
short: 18-Bit
int: 36-Bit
long: 36-Bit

IIRC, the terms state that those typedefs are present _if_ there are
suitable types on the system. In the case of a 9 bit byte, they just
wouldn't be there.

What you would get would be int_least8_t etc though, I think.

Uli
 
S

Schraalhans Keukenmeester

Frederick said:
Here's an excerpt from the Dinkumware library reference:
__________
| uint8_t, uint16_t, uint32_t, uint64_t
|
| The types each specify an unsigned integer type
| whose representation has exactly eight, 16, 32,
| or 64 bits, respectively.
__________

How could that be possible if we had a 36-Bit system such as the following?

char: 9-Bit
short: 18-Bit
int: 36-Bit
long: 36-Bit
I suppose in order to warrant C99 standard compliance the compiler for
such a system would have to cater for the necessary translation and
storage methods. How it does that may not be the programmer's concern,
as long as he/she sticks to standard C.

A similar 'problem' exists for 64 bit variables on 32-bit machines. To
the programmer the long longs are available as if they were a system
default, yet the compiler translates all relevant code to multiple
32-bit manipulations.

Is there a particular (practical) reason for this question??
Sh.
 
T

Tim Prince

Frederick said:
Richard Heathfield posted:



I would understand if it read:

Where possible, the types "uint8_t, uint16_t, uint32_t, uint64_t"
denote an unsigned integer type whose representation has exactly...

But it doesn't say "where possible" -- it plainly states that these types
are available... ?
Perhaps Dinkumware don't support any 36-bit machines.
 
K

Keith Thompson

Frederick Gotham said:
Here's an excerpt from the Dinkumware library reference:
__________
| uint8_t, uint16_t, uint32_t, uint64_t
|
| The types each specify an unsigned integer type
| whose representation has exactly eight, 16, 32,
| or 64 bits, respectively.
__________

How could that be possible if we had a 36-Bit system such as the following?

char: 9-Bit
short: 18-Bit
int: 36-Bit
long: 36-Bit

It isn't. The uintN_t types are optional.
 
J

Jack Klein

It isn't. The uintN_t types are optional.

Actually, "semi optional" would be more accurate. If an
implementation provides any or all types which meet the definition,
namely exactly that many bits, no padding, and 2's complement
representation for negative values in the signed types, it is required
to provide the appropriate typedefs.
 
J

Jack Klein

Here's an excerpt from the Dinkumware library reference:
__________
| uint8_t, uint16_t, uint32_t, uint64_t
|
| The types each specify an unsigned integer type
| whose representation has exactly eight, 16, 32,
| or 64 bits, respectively.
__________

How could that be possible if we had a 36-Bit system such as the following?

char: 9-Bit
short: 18-Bit
int: 36-Bit
long: 36-Bit

Purchase and read a copy of the C standard, 1999 or later, and all
will be revealed to you.
 
C

Chris Hills

Frederick Gotham said:
Here's an excerpt from the Dinkumware library reference:
__________
| uint8_t, uint16_t, uint32_t, uint64_t
|
| The types each specify an unsigned integer type
| whose representation has exactly eight, 16, 32,
| or 64 bits, respectively.
__________

How could that be possible if we had a 36-Bit system such as the following?

char: 9-Bit
short: 18-Bit
int: 36-Bit
long: 36-Bit
Then create and use the following types.

uint9_t, uint18_t, uint36_t
 
T

Tom St Denis

Frederick said:
Here's an excerpt from the Dinkumware library reference:
__________
| uint8_t, uint16_t, uint32_t, uint64_t
|
| The types each specify an unsigned integer type
| whose representation has exactly eight, 16, 32,
| or 64 bits, respectively.
__________

How could that be possible if we had a 36-Bit system such as the following?

char: 9-Bit
short: 18-Bit
int: 36-Bit
long: 36-Bit

The uint types are OPTIONAL. If they exist they are guaranteed to be a
given size [or at least represent the given range, padding bits
omitted...].

This is why using them is dangerous since any C99 conforming compiler
could not have them.

Tom
 
F

Flash Gordon

Tom said:
Frederick said:
Here's an excerpt from the Dinkumware library reference:
__________
| uint8_t, uint16_t, uint32_t, uint64_t
|
| The types each specify an unsigned integer type
| whose representation has exactly eight, 16, 32,
| or 64 bits, respectively.
__________

How could that be possible if we had a 36-Bit system such as the following?

char: 9-Bit
short: 18-Bit
int: 36-Bit
long: 36-Bit

The uint types are OPTIONAL. If they exist they are guaranteed to be a
given size [or at least represent the given range, padding bits
omitted...].

This is why using them is dangerous since any C99 conforming compiler
could not have them.

Or it is safe because if your code relies on a specific width, and there
are sometimes good reasons for doing this, then it is guaranteed that it
won't compile on any system where it would not work.
 
E

ena8t8si

Tom said:
Frederick said:
Here's an excerpt from the Dinkumware library reference:
__________
| uint8_t, uint16_t, uint32_t, uint64_t
|
| The types each specify an unsigned integer type
| whose representation has exactly eight, 16, 32,
| or 64 bits, respectively.
__________

How could that be possible if we had a 36-Bit system such as the following?

char: 9-Bit
short: 18-Bit
int: 36-Bit
long: 36-Bit

The uint types are OPTIONAL. If they exist they are guaranteed to be a
given size [or at least represent the given range, padding bits
omitted...].

This is why using them is dangerous since any C99 conforming compiler
could not have them.

Types like uint32_t are required if the implementation
has a standard integer type that matches it.
 
H

Harald van =?UTF-8?B?RMSzaw==?=

Frederick said:
Here's an excerpt from the Dinkumware library reference:
__________
| uint8_t, uint16_t, uint32_t, uint64_t
|
| The types each specify an unsigned integer type
| whose representation has exactly eight, 16, 32,
| or 64 bits, respectively.
__________

How could that be possible if we had a 36-Bit system such as the
following?

char: 9-Bit
short: 18-Bit
int: 36-Bit
long: 36-Bit

The uint types are OPTIONAL. If they exist they are guaranteed to be a
given size [or at least represent the given range, padding bits
omitted...].

This is why using them is dangerous since any C99 conforming compiler
could not have them.

Types like uint32_t are required if the implementation
has a standard integer type that matches it.

Two nits: uint32_t is required if the implementation has an integer type
(standard integer type or extended integer type) that matches it, and the
implementation also has an integer type that matches int32_t.
 
E

ena8t8si

Harald said:
Frederick Gotham wrote:
Here's an excerpt from the Dinkumware library reference:
__________
| uint8_t, uint16_t, uint32_t, uint64_t
|
| The types each specify an unsigned integer type
| whose representation has exactly eight, 16, 32,
| or 64 bits, respectively.
__________

How could that be possible if we had a 36-Bit system such as the
following?

char: 9-Bit
short: 18-Bit
int: 36-Bit
long: 36-Bit

The uint types are OPTIONAL. If they exist they are guaranteed to be a
given size [or at least represent the given range, padding bits
omitted...].

This is why using them is dangerous since any C99 conforming compiler
could not have them.

Types like uint32_t are required if the implementation
has a standard integer type that matches it.

Two nits: uint32_t is required if the implementation has an integer type
(standard integer type or extended integer type) that matches it,

Yes. Notice I spelled if with only one f.
and the
implementation also has an integer type that matches int32_t.

That's not how I read the requirement. An int32_t must
be provided if there's a type that matches it; a uint32_t
must be provided if there's a type that matches it; but
either can be required without the existence of the other.
 
H

Harald van =?UTF-8?B?RMSzaw==?=

Tom St Denis wrote:
Frederick Gotham wrote:
Here's an excerpt from the Dinkumware library reference:
__________
| uint8_t, uint16_t, uint32_t, uint64_t
|
| The types each specify an unsigned integer type
| whose representation has exactly eight, 16, 32,
| or 64 bits, respectively.
__________

How could that be possible if we had a 36-Bit system such as the
following?

char: 9-Bit
short: 18-Bit
int: 36-Bit
long: 36-Bit

The uint types are OPTIONAL. If they exist they are guaranteed to be
a given size [or at least represent the given range, padding bits
omitted...].

This is why using them is dangerous since any C99 conforming compiler
could not have them.

Types like uint32_t are required if the implementation
has a standard integer type that matches it.

Two nits: uint32_t is required if the implementation has an integer type
(standard integer type or extended integer type) that matches it,

Yes. Notice I spelled if with only one f.
and the
implementation also has an integer type that matches int32_t.

That's not how I read the requirement. An int32_t must
be provided if there's a type that matches it; a uint32_t
must be provided if there's a type that matches it; but
either can be required without the existence of the other.

7.18.1p1:
"When typedef names differing only in the absence or presence of the initial
u are deï¬ned, they shall denote corresponding signed and unsigned types as
described in 6.2.5; an implementation providing one of these corresponding
types shall also provide the other."

I'll admit 7.18.1.1p3 is ambiguous, but your (unfortunately legitimate)
interpretation of it leads to ridiculous results, such as any
implementation with CHAR_BIT==8 and no two's complement being
nonconforming.
 
E

ena8t8si

Harald said:
(e-mail address removed) wrote:


Tom St Denis wrote:
Frederick Gotham wrote:
Here's an excerpt from the Dinkumware library reference:
__________
| uint8_t, uint16_t, uint32_t, uint64_t
|
| The types each specify an unsigned integer type
| whose representation has exactly eight, 16, 32,
| or 64 bits, respectively.
__________

How could that be possible if we had a 36-Bit system such as the
following?

char: 9-Bit
short: 18-Bit
int: 36-Bit
long: 36-Bit

The uint types are OPTIONAL. If they exist they are guaranteed to be
a given size [or at least represent the given range, padding bits
omitted...].

This is why using them is dangerous since any C99 conforming compiler
could not have them.

Types like uint32_t are required if the implementation
has a standard integer type that matches it.

Two nits: uint32_t is required if the implementation has an integer type
(standard integer type or extended integer type) that matches it,

Yes. Notice I spelled if with only one f.
and the
implementation also has an integer type that matches int32_t.

That's not how I read the requirement. An int32_t must
be provided if there's a type that matches it; a uint32_t
must be provided if there's a type that matches it; but
either can be required without the existence of the other.

7.18.1p1:
"When typedef names differing only in the absence or presence of the initial
u are defined, they shall denote corresponding signed and unsigned types as
described in 6.2.5; an implementation providing one of these corresponding
types shall also provide the other."

Interesting. This can be read either as saying that
an implementation can't provide uint32_t unless it
also provides int32_t (and vice versa), or as saying
that if an implementation has a type that matches
uint32_t it must also provide a type that matches
int32_t (and vice versa) (and similarly for 8,16,64).
I'll admit 7.18.1.1p3 is ambiguous, but your (unfortunately legitimate)
interpretation of it leads to ridiculous results, such as any
implementation with CHAR_BIT==8 and no two's complement being
nonconforming.

An implementation with CHAR_BIT==8 and ones complement
for signed char would simply be required to have an
extended integer type with size 1 and that uses twos
complement for its signed type. There's no reason an
implementation can't have both ones complement types
and twos complement types.

In any case, good to have 7.18.1p3 pointed out.
 
H

Harald van =?UTF-8?B?RMSzaw==?=

Harald van Dijk wrote:
(e-mail address removed) wrote:


Tom St Denis wrote:
Frederick Gotham wrote:
Here's an excerpt from the Dinkumware library reference:
__________
| uint8_t, uint16_t, uint32_t, uint64_t
|
| The types each specify an unsigned integer type
| whose representation has exactly eight, 16, 32,
| or 64 bits, respectively.
__________

How could that be possible if we had a 36-Bit system such as the
following?

char: 9-Bit
short: 18-Bit
int: 36-Bit
long: 36-Bit

The uint types are OPTIONAL. If they exist they are guaranteed to
be a given size [or at least represent the given range, padding
bits omitted...].

This is why using them is dangerous since any C99 conforming
compiler could not have them.

Types like uint32_t are required if the implementation
has a standard integer type that matches it.

Two nits: uint32_t is required if the implementation has an integer
type (standard integer type or extended integer type) that matches it,

Yes. Notice I spelled if with only one f.

and the
implementation also has an integer type that matches int32_t.

That's not how I read the requirement. An int32_t must
be provided if there's a type that matches it; a uint32_t
must be provided if there's a type that matches it; but
either can be required without the existence of the other.

7.18.1p1:
"When typedef names differing only in the absence or presence of the
initial u are defined, they shall denote corresponding signed and
unsigned types as described in 6.2.5; an implementation providing one of
these corresponding types shall also provide the other."

Interesting. This can be read either as saying that
an implementation can't provide uint32_t unless it
also provides int32_t (and vice versa), or as saying
that if an implementation has a type that matches
uint32_t it must also provide a type that matches
int32_t (and vice versa) (and similarly for 8,16,64).
I'll admit 7.18.1.1p3 is ambiguous, but your (unfortunately legitimate)
interpretation of it leads to ridiculous results, such as any
implementation with CHAR_BIT==8 and no two's complement being
nonconforming.

An implementation with CHAR_BIT==8 and ones complement
for signed char would simply be required to have an
extended integer type with size 1 and that uses twos
complement for its signed type.

Meaning if it has no such two's complement type, it cannot be conforming.
That's what I said, isn't it?
There's no reason an
implementation can't have both ones complement types
and twos complement types.

The standard doesn't prohibit it, but hardware limitations are a possible
reason.
In any case, good to have 7.18.1p3 pointed out.

I'm not sure if you mean 7.18.1p1 or 7.18.1.1p3, but either way :)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,906
Latest member
SkinfixSkintag

Latest Threads

Top