🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.std.c++
Article #2838

Re: Stuff C++ needs

#2838
From: Steve Clamage
Date: Mon, 04 Dec 1995 22:16
43 lines
2609 bytes
In article rba@news.csus.edu, dick@silicon.csci.csusb.edu (Dr. Richard Botting) writes:
>
>However, you mentioned:
>: and they require at least the following ranges of each type:
>Does this allow someone to have larger ranges (more bits)?
>For example 66 bit ints (the fastest fixed point on a CDC Cyber)
>certainly includes: -32767 .. 32767

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++.

>Any way I guess we can always
>	enum{ lo=-32767, hi=32767} signed16bit;
>and so on?

There is no requirement that any type have a specific number of bits;
the only requirements are pure binary encoding and specified minimum ranges.
For one thing, a specific number of bits might be impossible on
some architecture. A 36-bit machine, for example, won't have a 16-bit
data type. It might have 9-bit bytes and an 18-bit data type.

If you need to restrict yourself to a fixed number of bits to match
an external data format, you can use bitfields in a struct. Such code
is inherently unportable (byte size, byte order, padding requirements, 
1's complement vs 2's complement, etc) and should be restricted to
interface modules that may need to be recoded for each new platform.
In portable code, assume only the minimum ranges required by the standard.

That problem is particularly easy to resolve in C++. Create a class that
manages the bit-fiddling, and reimplement only that class for each
different architecture. The remainder of the source code is unchanged.
---
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. ]
Technical Details
Message-ID: <49vqon$mvs@engnews2.Eng.Sun.COM>
Path: arc1-ca.pugleaf.net!engnews2.Eng.Sun.COM!taumet!clamage
References: <49tnkd$rba@news.csus.edu>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!engnews2.Eng.Sun.COM!taumet!clamage
From: clamage@Eng.sun.com (Steve Clamage)
Newsgroups: comp.std.c++
Subject: Re: Stuff C++ needs
Date: 4 Dec 1995 22:16:36 GMT
Organization: Sun Microsystems Inc.
Approved: clamage@eng.sun.com (comp.std.c++)
Message-ID: <49vqon$mvs@engnews2.Eng.Sun.COM>
References: <49tnkd$rba@news.csus.edu>
Reply-To: clamage@Eng
NNTP-Posting-Host: taumet.eng.sun.com
Content-Type: text
X-Nntp-Posting-Host: taumet.eng.sun.com
Content-Length: 1817
X-Lines: 39
Originator: clamage@taumet