Topic: How to write REALLY PORTABLE code dealing with bits (Was: How Big is a Byte?)


Author: scampi@dial.pipex.com (Mathew Hendry)
Date: 1999/08/06
Raw View
[crossposted to comp.std.c++ for comment]

On Tue, 03 Aug 1999 20:57:28 GMT, rawcswi@my-deja.com wrote:

>In article <37a73a5c.12127313@news.tripnet.se>,
>  blizzar@hem1.passagen.se wrote:
>> On Tue, 03 Aug 1999 16:09:46 GMT, math@vissci.com (Mathew Hendry)
>> wrote:
>> >: 1 == sizeof(char) <= sizeof(short) <= sizeof(int) <= sizeof(long)
>> >
>> >That is not strictly guaranteed. But the probability of it not being
>> >true in practice is negligable.
>>
>> What do you mean by strictly guaranteed?
>
>  [From the C++ Standard]
>
>2 There are four signed integer types: "signed char", "short int",
>  "int", and "long int."  In this list, each type provides at least as
>  much storage as those preceding it in the list.  Plain ints have the
>  natural size suggested by the architecture of the execution
>  environment; the other signed integer types are provided to meet
>  special needs.
>
>I guess that "as much storage" means sizeof is at least as large.

I'm not sure. Wouldn't it then have said "... each type _requires_ at
least as much storage as..."?

It seems backwards to say that int _provides_ sizeof(int) bytes of
storage. Rather, sizeof(int) bytes provides sufficient storage for an
int.

Are there any footnotes clarifying this? It's a purely academic
question, but I'm interested anyway. ;)

-- Mat.
---
[ 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 Curran" <JamesCurran@msn.com>
Date: 1999/08/07
Raw View
    The standard is essentially the contract between the compiler vendor and
the developer (compiler user).   The developer would care how much storage
it "provides" (ie, how big a number he can stuff there).  Only the
implementor should care how much storage is "required".

    A long time ago, I worked on a machine inwhich the smallest addressable
storage was a two byte word (ie, the two bytes at address 0 were distinct
from the two bytes at address 1).  I didn't use C or C++ on that machine,
but I'd have to guess that both it's chars and ints would "require" 16-bits,
but the chars would only "provide" 8-bits.

--
Truth,
   James [MVP]
http://www.NJTheater.Com       -and-
http://www.NJTheater.Com/JamesCurran

Mathew Hendry wrote in message <37ab1a3c.166701821@news.dial.pipex.com>...
>[crossposted to comp.std.c++ for comment]
>I'm not sure. Wouldn't it then have said "... each type _requires_ at
>least as much storage as..."?
>
>It seems backwards to say that int _provides_ sizeof(int) bytes of
>storage. Rather, sizeof(int) bytes provides sufficient storage for an
>int.
---
[ 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/08/07
Raw View
In article <073770453150689CPIMSSMTPU07@email.msn.com>, James Curran
<JamesCurran@msn.com> writes
>    A long time ago, I worked on a machine inwhich the smallest addressable
>storage was a two byte word (ie, the two bytes at address 0 were distinct
>from the two bytes at address 1).  I didn't use C or C++ on that machine,
>but I'd have to guess that both it's chars and ints would "require" 16-bits,
>but the chars would only "provide" 8-bits.

Not necessarily.  A void * could contain a machine address and an offset
(that style is used on several large machines where there is a large
overhead for using addresses that are not multiples of 4, 8 or
whatever).  char * would be the same format as void * but pointers for
larger objects would only store the address sans offset.


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: Adam Spragg <adam_spragg@novaclarion.com>
Date: 1999/08/08
Raw View
James Curran wrote:
>     A long time ago, I worked on a machine inwhich the smallest addressable
> storage was a two byte word (ie, the two bytes at address 0 were distinct
> from the two bytes at address 1).  I didn't use C or C++ on that machine,
> but I'd have to guess that both it's chars and ints would "require" 16-bits,
> but the chars would only "provide" 8-bits.

Or it could have provided 16-bit chars. You could have a real
machine-native unicode character set on it. Cool!

Adam

--
Apparently [...] police in many lands are now complaining that local
arrestees are insisting on having their Miranda rights read to them,
just like perps in American TV cop shows. When it's explained to them
that they are in a different country, where those rights do not exist,
they become outraged. Starsky and Hutch reruns, dubbed into diverse
languages, may turn out, in the long run, to be a greater force for
human rights than the [United States] Declaration of Independence.
-- Neal Stephenson (Cryptonomicon -
http://www.io.com/~mccoy/beginning_print.html)

----------------
The opinions expressed in this email are mine alone, and do not
neccesarily represent those of my employer, my parents, or the people
who wrote the email software I use.
---
[ 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              ]