🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

6 total messages Started by brian (b.c.) white Thu, 07 Dec 1995 17:55
Re: Stuff C++ needs
#2904
Author: brian (b.c.) white
Date: Thu, 07 Dec 1995 17:55
21 lines
1508 bytes
In article <49vqon$mvs@engnews2.eng.sun.com>,
Steve Clamage <clamage@Eng> wrote:
>Yes, of course. This was true in C as well. The requirements are that
>	sizeof(char) <= sizeof(short) <= sizeof(int) <= sizeof(long)
>They are allowed to be all the same size, for example, and you can look
>in K&R1 to find examples. This situation -- no predetermined size for
>any built-in type -- has been true since the beginning of C, and is
>still true in C++.

I thought I read somewhere that C++ guarantees a "char" to be 8 bits (or
was that "one byte"?).

                                        Brian
                                 ( bcwhite@bnr.ca )

-------------------------------------------------------------------------------
    In theory, theory and practice are the same.  In practice, they're not.

[ comp.std.c++ is moderated.  Submission address: std-c++@ncar.ucar.edu.
  Contact address: std-c++-request@ncar.ucar.edu.  The moderation policy
  is summarized in http://dogbert.lbl.gov/~matt/std-c++/policy.html. ]
Re: Stuff C++ needs
#2912
Author: Steve Clamage
Date: Fri, 08 Dec 1995 04:09
31 lines
1584 bytes
In article ghm@bcarh8ab.bnr.ca, "brian (b.c.) white" <bcwhite@bnr.ca> writes:
>
>I thought I read somewhere that C++ guarantees a "char" to be 8 bits (or
>was that "one byte"?).

In C and C++, the size of a char or a byte is always implementation-defined,
and neither is required to be exactly 8 bits. A char or a byte could have more
(or fewer) than 8 bits.

Excerpts from the C++ draft standard:

[intro.memory]  1.5 The C++ memory model
The fundamental storage unit in the C++ memory model is the byte. A byte is
at least large enough to contain any member of the basic execution character
set and is composed of a contiguous sequence of bits, the number of which
is implementation­defined.  ...

[basic.fundamental]  3.9.1 Fundamental types
Objects declared as characters (char) shall be large enough to store any
member of the implementation's basic character set.  ...  
---
Steve Clamage, stephen.clamage@eng.sun.com




---
[ comp.std.c++ is moderated.  Submission address: std-c++@ncar.ucar.edu.
  Contact address: std-c++-request@ncar.ucar.edu.  The moderation policy
  is summarized in http://dogbert.lbl.gov/~matt/std-c++/policy.html. ]
Re: Stuff C++ needs
#2917
Author: Charley Bay (Contract)
Date: Fri, 08 Dec 1995 16:13
29 lines
1935 bytes
: In article ghm@bcarh8ab.bnr.ca, "brian (b.c.) white" <bcwhite@bnr.ca> writes:
: >I thought I read somewhere that C++ guarantees a "char" to be 8 bits (or
: >was that "one byte"?).

Steve Clamage (clamage@Eng.Sun.COM) responded:
: In C and C++, the size of a char or a byte is always implementation-defined,
: and neither is required to be exactly 8 bits. A char or a byte could have more
: (or fewer) than 8 bits.
: [snip, standard reference]

Right--remember back to the old C days?  A "byte" was defined
to be a sizeof() of ONE, and all other data types were based on
multiples of ONE.  (An "int" was TWO on MS-DOS platforms, or
FOUR on UNIX platforms, etc.)  The platform determined exactly what
that ONE was, and the source code was never supposed to care.

This was a major boon for portability (although I acknowledge
it's harder to guess ranges).

--
--charley                              #include <stdisclaimer.h>
charleyb@gr.hp.com    -or-    charley@agrostis.nrel.colostate.edu



[ comp.std.c++ is moderated.  Submission address: std-c++@ncar.ucar.edu.
  Contact address: std-c++-request@ncar.ucar.edu.  The moderation policy
  is summarized in http://dogbert.lbl.gov/~matt/std-c++/policy.html. ]
Re: Stuff C++ needs
#2921
Author: Jerry Coffin
Date: Fri, 08 Dec 1995 21:20
22 lines
1240 bytes
"brian (b.c.) white" <bcwhite@bnr.ca> wrote:

[ ... ]
>I thought I read somewhere that C++ guarantees a "char" to be 8 bits (or
>was that "one byte"?).

One byte.  The number of bits in a char can be found in limits.h as
CHAR_BIT. (Actually, the current name is something like climitsh instead
of limits.h)
    Later,
    Jerry.

/* I can barely express my own opinions; I certainly can't
 * express anybody else's.
 *
 * The universe is a figment of its own imagination.
 */


[ comp.std.c++ is moderated.  Submission address: std-c++@ncar.ucar.edu.
  Contact address: std-c++-request@ncar.ucar.edu.  The moderation policy
  is summarized in http://dogbert.lbl.gov/~matt/std-c++/policy.html. ]
Re: Stuff C++ needs
#2924
Author: Tony Cook
Date: Thu, 14 Dec 1995 04:52
14 lines
1138 bytes
Steve Clamage (clamage@Eng.Sun.COM) wrote:
: In C and C++, the size of a char or a byte is always implementation-defined,
: and neither is required to be exactly 8 bits. A char or a byte could have more
: (or fewer) than 8 bits.

Isn't CHAR_BITS (in limits.h) required to be at least 8 (with the
obvious implication that char is at least 8 bits)?
-- 
        Tony Cook - tony@online.tmx.com.au
                    100237.3425@compuserve.com

[ comp.std.c++ is moderated.  Submission address: std-c++@ncar.ucar.edu.
  Contact address: std-c++-request@ncar.ucar.edu.  The moderation policy
  is summarized in http://dogbert.lbl.gov/~matt/std-c++/policy.html. ]
Re: Stuff C++ needs
#2938
Author: Jerry Coffin
Date: Thu, 14 Dec 1995 20:24
22 lines
1375 bytes
tony@online.tmx.com.au (Tony Cook) wrote:

[ ... ] 
>Isn't CHAR_BITS (in limits.h) required to be at least 8 (with the
>obvious implication that char is at least 8 bits)?

Yes.  (or more accurately, it's CHAR_BIT, but...)  Anyhow, there's more
than an implication involved.  The C standard specifically says "number
of bits for the smallest object that is not a bit-field"...
    Later,
    Jerry.

/* I can barely express my own opinions; I certainly can't
 * express anybody else's.
 *
 * The universe is a figment of its own imagination.
 */


[ comp.std.c++ is moderated.  Submission address: std-c++@ncar.ucar.edu.
  Contact address: std-c++-request@ncar.ucar.edu.  The moderation policy
  is summarized in http://dogbert.lbl.gov/~matt/std-c++/policy.html. ]
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads