Connecting Tech Pros Worldwide Help | Site Map

Two questions on ISO C++

  #1  
Old October 31st, 2007, 09:35 PM
john
Guest
 
Posts: n/a
I want to verify my memory.

0 doesn't necessarily mean all-bits-zero in integrals, and 1 byte is not
necessarily 8 bits (that's why we have numeric_limits<unsigned
char>::digits). Right?

  #2  
Old October 31st, 2007, 09:35 PM
Victor Bazarov
Guest
 
Posts: n/a

re: Two questions on ISO C++


john wrote:
Quote:
I want to verify my memory.
>
0 doesn't necessarily mean all-bits-zero in integrals, and 1 byte is
not necessarily 8 bits (that's why we have numeric_limits<unsigned
char>::digits). Right?
No, 0 is all bits clear in integrals (all reps acceptable by C++ have
that representation of 0). Yes, 1 byte can have more than 8 bits.

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask


  #3  
Old October 31st, 2007, 10:15 PM
peter koch
Guest
 
Posts: n/a

re: Two questions on ISO C++


On 31 Okt., 21:26, john <j...@no.spamwrote:
Quote:
I want to verify my memory.
>
0 doesn't necessarily mean all-bits-zero in integrals, and 1 byte is not
necessarily 8 bits (that's why we have numeric_limits<unsigned
char>::digits). Right?
As Victor wrote, all bits will be zero in integrals, but the null
pointer might not have an all zeroes representation (even though using
0 is perfectly legal (and how I prefer to write "null")).

Peter

  #4  
Old November 1st, 2007, 10:35 AM
James Kanze
Guest
 
Posts: n/a

re: Two questions on ISO C++


On Oct 31, 9:26 pm, john <j...@no.spamwrote:
Quote:
I want to verify my memory.
Quote:
0 doesn't necessarily mean all-bits-zero in integrals,
Yes and no. The standard requires a "pure binary"
representation for integrals, which means that all value bits 0
must represent the value 0. On the other hand, the standard
allows representations which have both a positive and a negative
0, one of which will not have all bits 0. It also allows
"padding" bits, which may be anything.

So roughly speaking: memset'ing an integral type with 0's
guarantees a zero representation, but the fact memcmp with a lot
of 0 bytes returns non-0 doesn't mean that the value isn't zero.

As far as the standard is concerned, too, the above only holds
for integral types. All bits zero (or memset'ing the object to
0) doesn't guarantee a 0.0 value for floating point, nor a null
pointer for a pointer. (In practice, I've never heard of an
implementation where it didn't work for floating point---perhaps
a Unisys series A. There very definitly have been machines
where it didn't work for pointers, however.)
Quote:
and 1 byte is not necessarily 8 bits (that's why we have
numeric_limits<unsigned char>::digits). Right?
Right. Standard English usage, that one. A byte has never been
necessarily 8 bits (and in fact, in the original usage at IBM,
was 6 bits). Of course, the C++ standard does use the word in a
somewhat different since, since it allows the size of a byte to
be the same as the size of a word, and requires it to be at
least 8 bits, and that the number of bytes in a word must be an
integer. (Common usage on the PDP-10 was 5 seven bit bytes in a
36 bit word. The byte size was programmable, however, and
presumably any C/C++ implementations used 4 nine bit bytes.)

--
James Kanze (GABI Software) email:james.kanze@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34


Closed Thread


Similar Threads
Thread Thread Starter Forum Replies Last Post
Extracting files from an ISO image? Ant answers 4 January 3rd, 2008 09:45 AM
Two question about signal handlers Free Bird answers 7 November 15th, 2005 01:05 AM
Two questions Henry Su answers 4 July 23rd, 2005 01:25 PM
two questions Darius Fatakia answers 3 July 20th, 2005 03:35 PM