Topic: Data type ranges


Author: James.Kanze@dresdner-bank.com
Date: 1999/09/21
Raw View
In article <37E16473.D33303DA@ihug.co.nz>,
  Ross Smith <ross.s@ihug.co.nz> wrote:

> > If you care about real implementations, yes there are real
> > implementations that use different sizes for these.  For a couple of
> > examples: the compilers for what used to be Crays (now called
> > something like "SGI Origin 2000") uses 8 bits for char's, and 64
bits
> > for ALL other sizes.  The compilers for Tru64 UNIX (aka Digital
UNIX)
> > use 64 bits for long.

If you care about real implementations for C, there have been several
with notably different sizes -- K&R mention one with 9 bit char's, if I
remember correctly, and on the Unisys Series A, all integral types
except char had 48 bits (AND signed magnitude, AND reserved bits in the
representation).  I think that there have also been implementations
where sizeof( char* ) !=3D sizeof( int* ) as well.

Most, if not all, of these belong to the past, however.

> When this came up on another newsgroup recently, I was told that there
> is at least one existing implementation (for a DSP chip) that uses 64
> bits for *all* the arithmetic types, including char.

This is legal, but it does create problems in implementing the standard
library.  DSP's generally have a free-standing implementation, so this
is no problem.

--
James Kanze                   mailto: James.Kanze@dresdner-bank.com
Conseils en informatique orient=E9e objet/
                  Beratung in objekt orientierter Datenverarbeitung
Ziegelh=FCttenweg 17a, 60598 Frankfurt, Germany Tel. +49(069)63198627


Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.
---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]





Author: Ross Smith <ross.s@ihug.co.nz>
Date: 1999/09/17
Raw View
Jerry Coffin wrote:
>
> In floating point, that
> applies as well, with the list running: float, double, long double.
> The minimum ranges are also given for these; while they're more
> difficult to translate directly to bit sizes, they basically come out
> to a minimum of 32 bits for a float and 64 bits for a double or long
> double.

Not quite. Float has at least 6 decimal digits of precision, double and
long double at least 10, and all three types must have an exponent range
(in decimal) of at least +/-37. This translates to:

    float             [long] double
    ----------------  ----------------
     1 (sign)          1 (sign)
    20 (significand)  34 (significand)
     7 (exponent)      7 (exponent)
    ----------------  ----------------
    28 bits           42 bits

(or one less if you use the implicit-leading-1 trick in the significand)

> If you care about real implementations, yes there are real
> implementations that use different sizes for these.  For a couple of
> examples: the compilers for what used to be Crays (now called
> something like "SGI Origin 2000") uses 8 bits for char's, and 64 bits
> for ALL other sizes.  The compilers for Tru64 UNIX (aka Digital UNIX)
> use 64 bits for long.

When this came up on another newsgroup recently, I was told that there
is at least one existing implementation (for a DSP chip) that uses 64
bits for *all* the arithmetic types, including char.

--
Ross Smith <ross.s@ihug.co.nz> The Internet Group, Auckland, New Zealand
========================================================================
  "There are many technical details that make Linux attractive to the
  sort of people to whom technical details are attractive."   -- Suck
---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]





Author: isujan@my-deja.com
Date: 1999/09/15
Raw View
I read an article which said the following about the data type ranges

int and uint are system dependent( i.e. their size varies with the
system )

WHILE

char, uchar, short, ushort, long, float , double ar fixed in all
systems. Is this correct??? e.g. long is always 4 bytes.


Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.
---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]





Author: Ron Natalie <ron@sensor.com>
Date: 1999/09/15
Raw View


isujan@my-deja.com wrote:
>
> I read an article which said the following about the data type ranges
>
> int and uint are system dependent( i.e. their size varies with the
> system )
>
> WHILE
>
> char, uchar, short, ushort, long, float , double ar fixed in all
> systems. Is this correct??? e.g. long is always 4 bytes.
>
No it is not correct.  First off, there is no such type
as "uchar", "uint", or "ushort".  Second, they are not
fixed size.  The only guarantee you get is that short
is at least 16 bits and that
 sizeof (char) <= sizeof (short) <= sizeof(int) <= sizeof(long)
 sizeof (float) <= sizeof (double)



[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]






Author: Francis Glassborow <francis@robinton.demon.co.uk>
Date: 1999/09/16
Raw View
In article <7roff4$jj6$1@nnrp1.deja.com>, isujan@my-deja.com writes
>I read an article which said the following about the data type ranges
>
>int and uint are system dependent( i.e. their size varies with the
>system )
>
>WHILE
>
>char, uchar, short, ushort, long, float , double ar fixed in all
>systems. Is this correct??? e.g. long is always 4 bytes.

NO

uint, uchar and ushort are not types I guess you were just saving typing
and meant unsigned int ...


You missed signed char and long double.  And the answers are the same in
all cases.  The Standard, like the C Standard imposes minimum ranges on
each type though any type can support a wider range.


Francis Glassborow      Journal Editor, Association of C & C++ Users
64 Southfield Rd
Oxford OX4 1PA          +44(0)1865 246490
All opinions are mine and do not represent those of any organisation
---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]





Author: "Darin Adler" <darin@bentspoon.com>
Date: 1999/09/16
Raw View
Ron Natalie <ron@sensor.com> wrote:
> The only guarantee you get is that short is at least 16 bits and that
>  sizeof (char) <= sizeof (short) <= sizeof(int) <= sizeof(long)
>  sizeof (float) <= sizeof (double)

Actually, the C standard guarantees that:

    - char is at least 8 bits,
    - signed char can hold at least from -127 to 127,
    - unsigned char can hold at least from 0 to 255,
    - short can hold at least from -32767 to 32767,
    - unsigned short can hold at least from 0 to 65535,
    - long can hold at least from -2147483647 to 2147483647, and
    - unsigned long can hold at least from 0 to 4294967295.

In practice, this means that long must be at least 4 bytes for typical
systems with the typical definition of "byte".

There may be additional guarantees for floating point as well. These
are in the C standard and inherited by the C++ standard by reference,
not repeated there.

    -- Darin
---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]





Author: James Kuyper <kuyper@wizard.net>
Date: 1999/09/16
Raw View
isujan@my-deja.com wrote:
>
> I read an article which said the following about the data type ranges
>
> int and uint are system dependent( i.e. their size varies with the
> system )
>
> WHILE
>
> char, uchar, short, ushort, long, float , double ar fixed in all
> systems. Is this correct??? e.g. long is always 4 bytes.

It's pretty much complete nonsense.
uchar, uint,  and ushort are popular typedefs (POSIX?), but are not part
of the C++ standard.

char, unsigned char, and signed char are by definition 1 byte, but the
number of bits per byte can be different on different implementations.
All of the other basic types have minimum widths, but no maximum.
---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]





Author: jcoffin@taeus.com (Jerry Coffin)
Date: 1999/09/16
Raw View
In article <7roff4$jj6$1@nnrp1.deja.com>, isujan@my-deja.com says...
> I read an article which said the following about the data type ranges
>
> int and uint are system dependent( i.e. their size varies with the
> system )
>
> WHILE
>
> char, uchar, short, ushort, long, float , double ar fixed in all
> systems. Is this correct??? e.g. long is always 4 bytes.

The article you read is wrong.  The standard places certain minimum
sizes on types:

type  minimum size in bits
char  8
short   16
int  16
long  32

In the standard, these are (mostly) given in terms of minimum ranges
instead of bits, but the effect as essentially these sizes, as well as
the fact that in the list above, each must have a range at least as
large as any that precedes it in the list.  In floating point, that
applies as well, with the list running: float, double, long double.
The minimum ranges are also given for these; while they're more
difficult to translate directly to bit sizes, they basically come out
to a minimum of 32 bits for a float and 64 bits for a double or long
double.

If you care about real implementations, yes there are real
implementations that use different sizes for these.  For a couple of
examples: the compilers for what used to be Crays (now called
something like "SGI Origin 2000") uses 8 bits for char's, and 64 bits
for ALL other sizes.  The compilers for Tru64 UNIX (aka Digital UNIX)
use 64 bits for long.

--
    Later,
    Jerry.

The Universe is a figment of its own imagination.
---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]