Topic: Official c++ 64-bit integer data type


Author: philippe_mori@hotmail.com ("Philippe Mori")
Date: Mon, 21 Jul 2003 18:32:13 +0000 (UTC)
Raw View
""cody"" <deutronium@gmx.net> a    crit dans le message de
news:bf466n$auf1n$1@ID-176797.news.uni-berlin.de...
> > void foo (int16_t a, int16_t b)
> > {
> >   int32_t result;
> >
> >   result = a + b;
> > }
>
>
> you mean in the case if int would be 8 bits then:
>
> 300 + 200 = 88 and not 600
>
> because every integral expression where not type ios explicitely specified
> results int the int-type?
>
> --

If you want portable code then you would write something like:

int32_t foo(int16_t a, int16_t bn)
{
    int32_t result = a;
    result += b;
    return result;
}

---
[ 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://www.jamesd.demon.co.uk/csc/faq.html                       ]





Author: deutronium@gmx.net ("cody")
Date: Tue, 22 Jul 2003 22:56:15 +0000 (UTC)
Raw View
> If you want portable code then you would write something like:
>
> int32_t foo(int16_t a, int16_t bn)
> {
>     int32_t result = a;
>     result += b;
>     return result;
> }


better would be:

inline int32_t foo(int16_t a, int16_t bn)
{
     return (int32_t)a + b;
}

:-D

--
cody

[Freeware, Games and Humor]
www.deutronium.de.vu || www.deutronium.tk


---
[ 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://www.jamesd.demon.co.uk/csc/faq.html                       ]





Author: deutronium@gmx.net ("cody")
Date: Sun, 13 Jul 2003 06:01:13 +0000 (UTC)
Raw View
> Unfortunatly using the same names will not increase portability where
> it matters:
>
> int32_t = int16_t + int16_t;
>
> This example will have different results depending on the sizeof(int).


you add datatypes together????
what do you mean here?

--
cody

[Freeware, Games and Humor]
www.deutronium.de.vu || www.deutronium.tk


---
[ 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://www.jamesd.demon.co.uk/csc/faq.html                       ]





Author: Michiel.Salters@cmg.nl (Michiel Salters)
Date: Mon, 14 Jul 2003 19:10:39 +0000 (UTC)
Raw View
deutronium@gmx.net ("cody") wrote in message news:<beqfj3$7u1ck$1@ID-176797.news.uni-berlin.de>...
> > Unfortunatly using the same names will not increase portability where
> > it matters:
> >
> > int32_t = int16_t + int16_t;
> >
> > This example will have different results depending on the sizeof(int).
>
>
> you add datatypes together????
> what do you mean here?

Adding variables of the specified type together, e.g.

int16_t a = 1<<14;
int16_t b = 1<<14;

int32_t c = a + b;

The obvious result would be c = 1<<15, but in the addition
the types will be promoted to int. The result of the addition
will also be an int. Whether or not that overflows still
depends on the exact bitwidth of an int. c==-(1<<15) could
occur if ints are 16 bits.

Regards,
--
Michiel Salters

---
[ 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://www.jamesd.demon.co.uk/csc/faq.html                       ]





Author: richards_corden@hotmail.com (Richard Corden)
Date: Mon, 14 Jul 2003 21:58:47 +0000 (UTC)
Raw View
> > int32_t = int16_t + int16_t;
> >
> > This example will have different results depending on the sizeof(int).
>
>
> you add datatypes together????
> what do you mean here?
>

Sorry for the poor example...

void foo (int16_t a, int16_t b)
{
  int32_t result;

  result = a + b;
}

So, the value of result may be different for different sizes of int.


Regards

Richard.

--
Richard Corden
To reply remove 's' from address

---
[ 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://www.jamesd.demon.co.uk/csc/faq.html                       ]





Author: deutronium@gmx.net ("cody")
Date: Thu, 17 Jul 2003 01:43:53 +0000 (UTC)
Raw View
> void foo (int16_t a, int16_t b)
> {
>   int32_t result;
>
>   result = a + b;
> }


you mean in the case if int would be 8 bits then:

300 + 200 = 88 and not 600

because every integral expression where not type ios explicitely specified
results int the int-type?

--
cody

[Freeware, Games and Humor]
www.deutronium.de.vu || www.deutronium.tk


---
[ 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://www.jamesd.demon.co.uk/csc/faq.html                       ]





Author: tslettebo@chello.no.nospam (=?iso-8859-1?Q?Terje_Sletteb=F8?=)
Date: Fri, 20 Jun 2003 19:34:36 +0000 (UTC)
Raw View
"John Nagle" <nagle@animats.com> wrote in message
news:zW2Ha.1174$Jn1.106792148@newssvr14.news.prodigy.com...
> Michiel Salters wrote:
> > gkajmowi@tbaytel.net ("Garrett Kajmowicz") wrote in message
news:<pan.2003.06.02.00.33.11.338116@tbaytel.net>...
> >
> >>Apparently long long is not an official c++ standard for integer
type.
> >>Given that, what is the official 64-bit integer type for C++?
> >
> > There is no such type.
>
>      I regard that as a defect in the standard.
>
>      There's a direct impact on portability here.
>
>      The standard should define
>
> uint8_t
> uint16_t
> uint32_t
> uint64_t
> int8_t
> int16_t
> int32_t
> int64_t
>
> or something equivalent, for both C and C++.
> Most platforms have some set of typedefs to do something
> like this, but they're not uniform.  That's the definition
> of something that needs to be standardized.

These exact types, and more, exist in C99's <stdint.h> header
(http://www.dinkumware.com/manuals/reader.aspx?b=c/&h=stdint.html), and
there's a proposal to add this to the C++ Library TR, as well
(http://anubis.dkuug.dk/jtc1/sc22/wg21/docs/papers/2003/n1475.html#1).


Regards,

Terje

---
[ 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://www.jamesd.demon.co.uk/csc/faq.html                       ]





Author: nagle@animats.com (John Nagle)
Date: Sun, 15 Jun 2003 22:13:54 +0000 (UTC)
Raw View
Michiel Salters wrote:
> gkajmowi@tbaytel.net ("Garrett Kajmowicz") wrote in message news:<pan.2003.06.02.00.33.11.338116@tbaytel.net>...
>
>>Apparently long long is not an official c++ standard for integer type.
>>Given that, what is the official 64-bit integer type for C++?
>
>
> There is no such type.

     I regard that as a defect in the standard.

     There's a direct impact on portability here.

     The standard should define

 uint8_t
 uint16_t
 uint32_t
 uint64_t
 int8_t
 int16_t
 int32_t
 int64_t

or something equivalent, for both C and C++.
Most platforms have some set of typedefs to do something
like this, but they're not uniform.  That's the definition
of something that needs to be standardized.

Don't do this with some wierd leading or trailing underscore
names, either.  Make it useable.

    John Nagle
    Animats

---
[ 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://www.jamesd.demon.co.uk/csc/faq.html                       ]





Author: richards_corden@hotmail.com (Richard Corden)
Date: Mon, 16 Jun 2003 14:28:54 +0000 (UTC)
Raw View
nagle@animats.com (John Nagle) writes:

>     I regard that as a defect in the standard.
>
>     There's a direct impact on portability here.
>
>      The standard should define
>
>  uint8_t
>  uint16_t
>  uint32_t
>  uint64_t
>  int8_t
>  int16_t
>  int32_t
>  int64_t

Unfortunatly using the same names will not increase portability where
it matters:

int32_t = int16_t + int16_t;

This example will have different results depending on the sizeof(int).



Richard

--
Richard Corden
To reply remove 's' from address

---
[ 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://www.jamesd.demon.co.uk/csc/faq.html                       ]





Author: ron@sensor.com (Ron Natalie)
Date: Tue, 17 Jun 2003 01:38:21 +0000 (UTC)
Raw View
"John Nagle" <nagle@animats.com> wrote in message news:zW2Ha.1174$Jn1.106792148@newssvr14.news.prodigy.com...
> Michiel Salters wrote:
> > gkajmowi@tbaytel.net ("Garrett Kajmowicz") wrote in message news:<pan.2003.06.02.00.33.11.338116@tbaytel.net>...
> >
> >>Apparently long long is not an official c++ standard for integer type.
> >>Given that, what is the official 64-bit integer type for C++?
> >
> >
> > There is no such type.

C now has both an additional integral type (long long) and an include file with
a set of standard typedefs of the category:

intN_t                    // exactly N bits in int
int_leastN_t           //  smallest int with at least N bits.
int_fastN_t           // at least N bits and fast.

The latter distinguishes something like a machine where an 8 bit signed char is present but
slower than just using the 32 bit int type.

typedef signed char int_least8_t;
typedef int int_fast8_t;

>
> Don't do this with some wierd leading or trailing underscore
> names, either.  Make it useable.

The C philosophy for new keywords is to use _Cap when defining new keywords.    This would
also be fine for C++ because that is in the reserved part of the namespace.   They follow it up
with a header file that #defines it to something more common.

For example, bool type in C is _Bool and the header stdbool #defnes it to bool.


---
[ 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://www.jamesd.demon.co.uk/csc/faq.html                       ]





Author: kst@cts.com (Keith Thompson)
Date: Sat, 7 Jun 2003 21:39:06 +0000 (UTC)
Raw View
chris@bubblescope.net (Chris Jefferson) writes:
> Garrett Kajmowicz wrote:
> > Apparently long long is not an official c++ standard for integer
> > type. Given that, what is the official 64-bit integer type for C++?
> > Thanks.
>
> There isn't one
>
> Also, you can't assume int and long are 32 bit (or that they are the
> same size). In a 64-bit system int should be 64 bit (although often
> isn't for compatability reasons)

Another reason not to make int a 64-bit type, even on a 64-bit system,
is that doing so typically leaves a hole in the type system.  If char
is 8 bits and int is 64 bits, short will probably be either 16 bits or
32 bits; there's no way to have a predefined 16-bit type *and* a
predefined 32-bit type.  By using 8-bit char, 16-bit short, 32-bit
int, and 64-bit long, you can cover all sensible sizes.

C99 allows for extended integer types that could fill in the gaps, but
I don't know of any implementations that actually do this.  I don't
see any reference to extended integer types in the C++ standard, and I
don't know whether a conforming C++ implementation could provide them.

--
Keith Thompson (The_Other_Keith) kst@cts.com  <http://www.ghoti.net/~kst>
San Diego Supercomputer Center           <*>  <http://www.sdsc.edu/~kst>
Schroedinger does Shakespeare: "To be *and* not to be"

---
[ 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://www.jamesd.demon.co.uk/csc/faq.html                       ]





Author: gkajmowi@tbaytel.net ("Garrett Kajmowicz")
Date: Mon, 2 Jun 2003 01:05:31 +0000 (UTC)
Raw View
Apparently long long is not an official c++ standard for integer type.
Given that, what is the official 64-bit integer type for C++?

Thanks.

Garrett Kajmowicz
gkajmowi@tbaytel.net

---
[ 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://www.jamesd.demon.co.uk/csc/faq.html                       ]





Author: Michiel.Salters@cmg.nl (Michiel Salters)
Date: Mon, 2 Jun 2003 18:38:05 +0000 (UTC)
Raw View
gkajmowi@tbaytel.net ("Garrett Kajmowicz") wrote in message news:<pan.2003.06.02.00.33.11.338116@tbaytel.net>...
> Apparently long long is not an official c++ standard for integer type.
> Given that, what is the official 64-bit integer type for C++?

There is no such type.

Regards,
--
Michiel Salters

---
[ 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://www.jamesd.demon.co.uk/csc/faq.html                       ]





Author: cpdaniel@nospam.mvps.org ("Carl Daniel")
Date: Mon, 2 Jun 2003 18:38:11 +0000 (UTC)
Raw View
"Garrett Kajmowicz" wrote:
> Apparently long long is not an official c++ standard for integer type.
> Given that, what is the official 64-bit integer type for C++?

There is none - integral types don't officially have specific sizes in C++.

-cd

---
[ 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://www.jamesd.demon.co.uk/csc/faq.html                       ]





Author: jackklein@spamcop.net (Jack Klein)
Date: Mon, 2 Jun 2003 18:38:11 +0000 (UTC)
Raw View
On Mon, 2 Jun 2003 01:05:31 +0000 (UTC), gkajmowi@tbaytel.net
("Garrett Kajmowicz") wrote in comp.std.c++:

> Apparently long long is not an official c++ standard for integer type.
> Given that, what is the official 64-bit integer type for C++?
>
> Thanks.

C++ has no official standard for a 64-bit integer type, and neither
does C.  Since the 1999 standard update, C requires signed and
unsigned long long integer types, which must contain _at least_, but
not _exactly_, 64 bits.

C++ has no such requirements at this time.  A conforming C++
implementation need not provide an integer type longer than signed and
unsigned long int, which need contain no more than 32 bits.

--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++ ftp://snurse-l.org/pub/acllc-c++/faq

---
[ 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://www.jamesd.demon.co.uk/csc/faq.html                       ]





Author: ron@sensor.com ("Ron Natalie")
Date: Mon, 2 Jun 2003 18:38:43 +0000 (UTC)
Raw View
""Garrett Kajmowicz"" <gkajmowi@tbaytel.net> wrote in message news:pan.2003.06.02.00.33.11.338116@tbaytel.net...
> Apparently long long is not an official c++ standard for integer type.
> Given that, what is the official 64-bit integer type for C++?
>
With small exception, there is NO standard in C or C++ for specific type
sizes of anything.   There are some minimum sizes for each and a requirement
that each be at least as big as the smaller type.

long long was added to C after the C++ standard was published.    It's
presence in C++ is going to be dependent on the implementation.


---
[ 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://www.jamesd.demon.co.uk/csc/faq.html                       ]





Author: chris@bubblescope.net (Chris Jefferson)
Date: Mon, 2 Jun 2003 18:38:43 +0000 (UTC)
Raw View
Garrett Kajmowicz wrote:

> Apparently long long is not an official c++ standard for integer type.
> Given that, what is the official 64-bit integer type for C++?
>
> Thanks.

There isn't one

Also, you can't assume int and long are 32 bit (or that they are the
same size). In a 64-bit system int should be 64 bit (although often
isn't for compatability reasons)

Chris

---
[ 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://www.jamesd.demon.co.uk/csc/faq.html                       ]





Author: dxcoder@censored.fi ("dxcoder")
Date: Mon, 2 Jun 2003 18:38:49 +0000 (UTC)
Raw View
> Apparently long long is not an official c++ standard for integer type.
> Given that, what is the official 64-bit integer type for C++?

Officially there isn't even 32-bit integer, or 16-bit, or... there is just
guarantee that  x <= y <= z <= w ... where x,y,z,w,... are integer types.


---
[ 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://www.jamesd.demon.co.uk/csc/faq.html                       ]





Author: bop2@telia.com ("Bo Persson")
Date: Mon, 2 Jun 2003 20:04:51 +0000 (UTC)
Raw View
""Garrett Kajmowicz"" <gkajmowi@tbaytel.net> skrev i meddelandet
news:pan.2003.06.02.00.33.11.338116@tbaytel.net...
> Apparently long long is not an official c++ standard for integer
type.
> Given that, what is the official 64-bit integer type for C++?

There is none. The implementation can choose anu suitable, like int or
long.

>
> Thanks.
>
> Garrett Kajmowicz
> gkajmowi@tbaytel.net
>


Bo Persson
bop2@telia.com

---
[ 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://www.jamesd.demon.co.uk/csc/faq.html                       ]





Author: andys@despammed.com (Andy Sawyer)
Date: Mon, 2 Jun 2003 21:48:36 +0000 (UTC)
Raw View
In article <bbg03k$m54$1@phys-news1.kolumbus.fi>,
 on Mon, 2 Jun 2003 18:38:49 +0000 (UTC),
 dxcoder@censored.fi ("dxcoder") wrote:

> > Apparently long long is not an official c++ standard for integer type.
> > Given that, what is the official 64-bit integer type for C++?
>
> Officially there isn't even 32-bit integer, or 16-bit, or... there is just
> guarantee that  x <= y <= z <= w ... where x,y,z,w,... are integer
> types.

The guarantees are stronger than that, since there are also guarantees
on the minimum sizes of integer types, but none of those is 64 bit.
--
"Light thinks it travels faster than anything but it is wrong. No matter
 how fast light travels it finds the darkness has always got there first,
 and is waiting for it."                  -- Terry Pratchett, Reaper Man

---
[ 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://www.jamesd.demon.co.uk/csc/faq.html                       ]





Author: andys@despammed.com (Andy Sawyer)
Date: Mon, 2 Jun 2003 21:48:46 +0000 (UTC)
Raw View
In article <8WMCa.9762$mU6.14302@newsb.telia.net>,
 on Mon, 2 Jun 2003 20:04:51 +0000 (UTC),
 bop2@telia.com ("Bo Persson") wrote:

> ""Garrett Kajmowicz"" <gkajmowi@tbaytel.net> skrev i meddelandet
> news:pan.2003.06.02.00.33.11.338116@tbaytel.net...
> > Apparently long long is not an official c++ standard for integer
> type.
> > Given that, what is the official 64-bit integer type for C++?
>
> There is none. The implementation can choose anu suitable, like int or
> long.

Or none. There is no requirement for the existence of a 64-bit type
within an implementation.
--
"Light thinks it travels faster than anything but it is wrong. No matter
 how fast light travels it finds the darkness has always got there first,
 and is waiting for it."                  -- Terry Pratchett, Reaper Man

---
[ 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://www.jamesd.demon.co.uk/csc/faq.html                       ]





Author: dxcoder@censored.fi ("dxcoder")
Date: Tue, 3 Jun 2003 17:58:33 +0000 (UTC)
Raw View
> > Officially there isn't even 32-bit integer, or 16-bit, or... there is
just
> > guarantee that  x <= y <= z <= w ... where x,y,z,w,... are integer
> > types.
>
> The guarantees are stronger than that, since there are also guarantees
> on the minimum sizes of integer types, but none of those is 64 bit.

or 32, 33, 34 or 35-bit... and those guarantees you mention are...?


---
[ 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://www.jamesd.demon.co.uk/csc/faq.html                       ]





Author: johnchx2@yahoo.com (johnchx)
Date: Wed, 4 Jun 2003 22:51:16 +0000 (UTC)
Raw View
dxcoder@censored.fi ("dxcoder") wrote
> >
> > The guarantees are stronger than that, since there are also guarantees
> > on the minimum sizes of integer types, but none of those is 64 bit.
>
> or 32, 33, 34 or 35-bit... and those guarantees you mention are...?
>

IIRC, char is at least 8-bit, short is at least 16-bit, and long is at
least 32-bit.  I think these requirements are imposed by the C
standard (as requirements on the values of the macros defined in
<limits.h>) and are incorporated into C++ by reference.  IIRC.  ;-)

---
[ 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://www.jamesd.demon.co.uk/csc/faq.html                       ]





Author: jdennett@acm.org (James Dennett)
Date: Wed, 4 Jun 2003 22:55:14 +0000 (UTC)
Raw View
dxcoder wrote:
>>>Officially there isn't even 32-bit integer, or 16-bit, or... there is
>
> just
>
>>>guarantee that  x <= y <= z <= w ... where x,y,z,w,... are integer
>>>types.
>>
>>The guarantees are stronger than that, since there are also guarantees
>>on the minimum sizes of integer types, but none of those is 64 bit.
>
>
> or 32, 33, 34 or 35-bit... and those guarantees you mention are...?

A minimum size of 32 bits _is_ guaranteed for unsigned
long (quite clearly) and for plain long.  int is at least
16 bits, as is short.  char is at least 8 bits.  These
observations follow from the guaranteed ranges of these
types.

-- James.

---
[ 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://www.jamesd.demon.co.uk/csc/faq.html                       ]





Author: kanze@gabi-soft.fr
Date: Thu, 5 Jun 2003 18:00:55 +0000 (UTC)
Raw View
dxcoder@censored.fi ("dxcoder") wrote in message
news:<bbgplk$qpb$1@phys-news1.kolumbus.fi>...

> > > Officially there isn't even 32-bit integer, or 16-bit, or... there
> > > is just guarantee that x <= y <= z <= w ... where x,y,z,w,... are
> > > integer types.

> > The guarantees are stronger than that, since there are also
> > guarantees on the minimum sizes of integer types, but none of those
> > is 64 bit.

> or 32, 33, 34 or 35-bit... and those guarantees you mention are...?

   3.9.1/7: "The representations of integral types shall define values by
use of a pure binary numeration system."

C standard,    5.2.4.2.1 (explicitly included in the C++ standard by
reference in    18.2.2):

    [...] Their implementation-defined values shall be equal or greater
    in magnitude (absolue value) to those shown, with the same sign.

     -- number of bits for the smallest object that is not a bit-field
        (byte)

        CHAR_BIT                                     8

    [...]

     -- minimum value for an object of type short int

        SHRT_MIN                                -32767

     -- maximum value for an object of type short int

        SHRT_MAX                                 32767

     -- maximum value for an object of type unsigned short int

        USHRT_MAX                                65535

    [ditto for INT_MIN, INT_MAX and UINT_MAX]

     -- minimum value for an object of type long int

        LONG_MIN                           -2147483647

     -- maximum value for an object of type long int

        LONG_MAX                            2147483647

     -- maximum value for an object of type unsigned long int

        ULONG_MAX                           4294967295

The standard doesn't say any more explicitly, but I (and probably a lot
of mathematicians) would be interested in seeing an implementation which
meets these requirements in which a long was less then 32 bits or a
short or an int less than 16 bits.

Of course, greater values are possible.  On my machine, an int is 32
bits (rather than the minimum 16 bits required) and a long is 64 (rather
than the minimum 32).  I'm also aware of machines (that existed in the
past, et least) where CHAR_BIT is 9. The machine in question had 36 bit
ints.

With regards to portability, it might be interesting if someone were to
make a virtual machine with, say 9 bit characters, 18 bit shorts and
ints, and 36 bit longs, all using 2's complement, with -0 working as a
trapping representation.  I'll bet that there are a lot of "portable"
programs (including a lot of my own) which would not work as expected on
such a machine.

--
James Kanze             GABI Software             mailto:kanze@gabi-soft.fr
Conseils en informatique orient   e objet/
                           Beratung in objektorientierter Datenverarbeitung
11 rue de Rambouillet, 78460 Chevreuse, France, T   l. : +33 (0)1 30 23 45 16

---
[ 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://www.jamesd.demon.co.uk/csc/faq.html                       ]





Author: ron@sensor.com ("Ron Natalie")
Date: Thu, 5 Jun 2003 18:01:33 +0000 (UTC)
Raw View
"James Dennett" <jdennett@acm.org> wrote in message news:BtrDa.34065$Io.2939482@newsread2.prod.itd.earthlink.net...

>
> A minimum size of 32 bits _is_ guaranteed for unsigned
> long (quite clearly) and for plain long.

One thing to keep in mind, is that the range of the signed types isn't
necessarily that of the sized 2's complement number.    The standard
only says +/- 255 etc... (to allow for 1's complement machines, etc...).


---
[ 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://www.jamesd.demon.co.uk/csc/faq.html                       ]





Author: andys@despammed.com (Andy Sawyer)
Date: Thu, 5 Jun 2003 22:15:15 +0000 (UTC)
Raw View
In article <bbgplk$qpb$1@phys-news1.kolumbus.fi>,
 on Tue, 3 Jun 2003 17:58:33 +0000 (UTC),
 dxcoder@censored.fi ("dxcoder") wrote:

> > > Officially there isn't even 32-bit integer, or 16-bit, or... there is
> just
> > > guarantee that  x <= y <= z <= w ... where x,y,z,w,... are integer
> > > types.
> >
> > The guarantees are stronger than that, since there are also guarantees
> > on the minimum sizes of integer types, but none of those is 64 bit.
>
> or 32, 33, 34 or 35-bit... and those guarantees you mention are...?

char, signed char and signed char are all at least 8 bits
int, unsigned int, short and unsigned short are all at least 16 bits
long and unsigned long are at least 32 bits.

Regards,
 Andy S.
--
"Light thinks it travels faster than anything but it is wrong. No matter
 how fast light travels it finds the darkness has always got there first,
 and is waiting for it."                  -- Terry Pratchett, Reaper Man

---
[ 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://www.jamesd.demon.co.uk/csc/faq.html                       ]