473,386 Members | 1,908 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Two questions on ISO C++

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?

Oct 31 '07 #1
3 1386
john wrote:
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
Oct 31 '07 #2
On 31 Okt., 21:26, john <j...@no.spamwrote:
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

Oct 31 '07 #3
On Oct 31, 9:26 pm, john <j...@no.spamwrote:
I want to verify my memory.
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.)
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:ja*********@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
Nov 1 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: softwareengineer2006 | last post by:
All Interview Questions And Answers 10000 Interview Questions And Answers(C,C++,JAVA,DOTNET,Oracle,SAP) I have listed over 10000 interview questions asked in interview/placement test papers for...
0
by: connectrajesh | last post by:
INTERVIEWINFO.NET http://www.interviewinfo.net FREE WEB SITE AND SERVICE FOR JOB SEEKERS /FRESH GRADUATES NO ADVERTISEMENT
2
by: freepdfforjobs | last post by:
Full eBook with 4000 C#, JAVA,.NET and SQL Server Interview questions http://www.questpond.com/SampleInterviewQuestionBook.zip Download the JAVA , .NET and SQL Server interview sheet and rate...
4
by: Drew | last post by:
I posted this to the asp.db group, but it doesn't look like there is much activity on there, also I noticed that there are a bunch of posts on here pertaining to database and asp. Sorry for...
8
by: Krypto | last post by:
Hi, I have used Python for a couple of projects last year and I found it extremely useful. I could write two middle size projects in 2-3 months (part time). Right now I am a bit rusty and trying...
0
by: ramu | last post by:
C# Interview Questions and Answers8 http://allinterviewsbooks.blogspot.com/2008/07/c-interview-questions-and-answers8.html C# Interview Questions and Answers7...
1
by: ramu | last post by:
C# Interview Questions and Answers8 http://allinterviewsbooks.blogspot.com/2008/07/c-interview-questions-and-answers8.html C# Interview Questions and Answers7...
0
by: ramu | last post by:
C# Interview Questions and Answers8 http://allinterviewsbooks.blogspot.com/2008/07/c-interview-questions-and-answers8.html C# Interview Questions and Answers7...
0
by: reema | last post by:
EJB Interview Questions http://interviewdoor.com/technical/EJB-Interview-Questions.htm CSS Interview Questions http://interviewdoor.com/technical/CSS-Interview-Questions.htm C Interview Questions...
0
by: reema | last post by:
EJB Interview Questions http://interviewdoor.com/technical/EJB-Interview-Questions.htm CSS Interview Questions http://interviewdoor.com/technical/CSS-Interview-Questions.htm C Interview Questions...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.