473,566 Members | 2,784 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

sizeof requirements for fundamental types

I recently looked over the faq item relating to fundamental type sizes:
http://www.parashift.com/c++-faq-lit....html#faq-29.5
and was a bit surprised, as I had been taught more-or-less the same
thing, just not the minimum gaurantees for short and long.

"C++ guarantees a char is exactly one byte which is at least 8 bits,
short is at least 16 bits, int is at least 16 bits, and long is at least
32 bits."

I looked in Stroustrup's book, The C++ Programming Language, and sure
enough he explains it just as is quoted above (don't know how I passed
over that before - anyhow...). I went to look in my copy of the C++
Standard 1998-09-01 and could not locate this requirement. I've read in
other threads that a newer version was released... was this a change in
the new version or am I just looking in the wrong spot? I was looking
in section 3.9.1 Fundamental Types.

A second related question has to do with the newer version of the
standard. What is the format of this document? Is it just the changes
to the version I have, or is it a complete document representing the
current state of the C++ standard?

Thanks,
Kyle
Jul 23 '05 #1
3 1500
"Kyle Kolander" <kk*******@hotm ail.com> wrote in message
news:32kBe.1622 6$fV.8670@okepr ead06
I recently looked over the faq item relating to fundamental type
sizes: http://www.parashift.com/c++-faq-lit....html#faq-29.5
and was a bit surprised, as I had been taught more-or-less the same
thing, just not the minimum gaurantees for short and long.

"C++ guarantees a char is exactly one byte which is at least 8 bits,
short is at least 16 bits, int is at least 16 bits, and long is at
least 32 bits."

I looked in Stroustrup's book, The C++ Programming Language, and sure
enough he explains it just as is quoted above (don't know how I passed
over that before - anyhow...). I went to look in my copy of the C++
Standard 1998-09-01 and could not locate this requirement. I've read
in other threads that a newer version was released... was this a
change in the new version or am I just looking in the wrong spot? I
was looking in section 3.9.1 Fundamental Types.
You need to piece together different parts of the standard, draw appropriate
conclusions and so on. The same is true of the definition of a POD type and
some other things. This is one reason why it is generally easier to learn
from a textbook than from the Standard.
A second related question has to do with the newer version of the
standard. What is the format of this document? Is it just the
changes to the version I have, or is it a complete document
representing the current state of the C++ standard?


You can get the complete thing in a PDF file or an over-priced book here:

http://www.techstreet.com/cgi-bin/de...uct_id=1143945

You can get a more reasonably priced book version here:

http://www.amazon.com/exec/obidos/AS...558617-1965648
--
John Carson
Jul 23 '05 #2

"John Carson" <jc************ ****@netspace.n et.au> wrote in message
news:db******** ***@otis.netspa ce.net.au...
"Kyle Kolander" <kk*******@hotm ail.com> wrote in message
news:32kBe.1622 6$fV.8670@okepr ead06
I recently looked over the faq item relating to fundamental type
sizes: http://www.parashift.com/c++-faq-lit....html#faq-29.5
and was a bit surprised, as I had been taught more-or-less the same
thing, just not the minimum gaurantees for short and long.

"C++ guarantees a char is exactly one byte which is at least 8 bits,
short is at least 16 bits, int is at least 16 bits, and long is at
least 32 bits."

I looked in Stroustrup's book, The C++ Programming Language, and sure
enough he explains it just as is quoted above (don't know how I passed
over that before - anyhow...). I went to look in my copy of the C++
Standard 1998-09-01 and could not locate this requirement. I've read
in other threads that a newer version was released... was this a
change in the new version or am I just looking in the wrong spot? I
was looking in section 3.9.1 Fundamental Types.
You need to piece together different parts of the standard, draw

appropriate conclusions and so on. The same is true of the definition of a POD type and some other things. This is one reason why it is generally easier to learn
from a textbook than from the Standard.

OK. Well, I'm sure this question has been asked before, but I'll ask
anyhow... *sigh* Why are the minimum size guarantees for fundamental types
intentionally omitted from section 3.9.1 of the standard? If indeed these
guarantees can be inferred from other parts of the standard, and it is the
intent of the standards committee that these guarantees exist, then why are
they not listed in the most relevant section? I mean come on! I can't be
alone on this one... Is this an open issue for the next version of the
standard? I believe it should be. How does everyone feel about this? I
recall a recent thread from comp.std.c++ about making the standard more
intelligible... this seems to fall directly under that category.

I'm also curious from which sections of the standard can these minimum size
guarantees be inferred? It is not that I do not believe you, because I do
believe you; however, I would very much like to put together a "proof" of
how these requirements can be derived from the standard.

A second related question has to do with the newer version of the
standard. What is the format of this document? Is it just the
changes to the version I have, or is it a complete document
representing the current state of the C++ standard?
You can get the complete thing in a PDF file or an over-priced book here:

http://www.techstreet.com/cgi-bin/de...uct_id=1143945

You can get a more reasonably priced book version here:

http://www.amazon.com/exec/obidos/AS...558617-1965648

Customer reviews point out a terrible binding for the book... has anyone
purchased this book? What did you think of it?
Jul 23 '05 #3
"Kyle Kolander" <kk*******@hotm ail.com> wrote in message
news:vj******** ***@dfw-service2.ext.ra y.com

OK. Well, I'm sure this question has been asked before, but I'll ask
anyhow... *sigh* Why are the minimum size guarantees for fundamental
types intentionally omitted from section 3.9.1 of the standard? If
indeed these guarantees can be inferred from other parts of the
standard, and it is the intent of the standards committee that these
guarantees exist, then why are they not listed in the most relevant
section? I mean come on! I can't be alone on this one... Is this an
open issue for the next version of the standard? I believe it should
be. How does everyone feel about this? I recall a recent thread
from comp.std.c++ about making the standard more intelligible... this
seems to fall directly under that category.

I'm also curious from which sections of the standard can these
minimum size guarantees be inferred? It is not that I do not believe
you, because I do believe you; however, I would very much like to put
together a "proof" of how these requirements can be derived from the
standard.


I suspect that the minimum size guarantees may be inherited from C. Annex C
(appropriately enough) of the C++ standard discusses things inherited from C
(as well as differences from C), and this includes various constants like
INT_MIN. I am not sure of this, but it seems the most likely explanation.

As for the readability of the standard, it is not really intended as a
learning tool. I agree that it could be more readily intelligble than it is,
but re-writing it would be a massive effort and the result would undoubtedly
be "buggy" at first, causing nightmares for the implementers of compilers
trying to comply with the standard. Rather like a large code base, there is
a great reluctance to re-write it from scratch and the resources to do it
just aren't there. The fact that it is the product of a committee (with a
changing and diverse membership) is another reason for its current
character.

--
John Carson

Jul 23 '05 #4

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

Similar topics

2
2452
by: Xiangliang Meng | last post by:
Hi, all. What will we get from sizeof(a class without data members and virtual functions)? For example: class abnormity { public: string name() { return "abnormity"; }
8
1793
by: Kyle Kolander | last post by:
Sorry, I sent this to comp.std.c++ and meant to send it here as well... Why are the minimum size guarantees for fundamental types intentionally omitted from section 3.9.1 Fundamental types of the C++ standard? If indeed these guarantees can be inferred from other parts of the standard, and it is the intent of the standards committee that...
12
1251
by: Kevin | last post by:
I have two questions. I hope they are about C. I chose to post here instead of comp.unix.programmer (or some other) because I do think this is a C question. Question 1: %cat float.c main() { float **m = malloc(5 * sizeof(float*)); m = malloc( sizeof(float) );
6
10807
by: SB | last post by:
I feel dumb to ask because I bet this is a simple question... Looking at the code below, can someone please explain why I get two different values in my Marshal.SizeOf calls (see the commented lines)? TIA! sb
8
5896
by: Tony Houghton | last post by:
I'm writing a python program which reads input device events so it needs to know sizeof(struct timeval). By using the struct module I should be able to work out sizeof(long) from python, but I can't think of a way to measure non-fundamental types without including a little bit of C, which I'd rather avoid. How safe would I be assuming that...
19
1865
by: Abubakar | last post by:
Hi, lets say I have the following class: class AAA{}; if I do: sizeof(AAA) it gives me 1. Why is the size 1 ? Regards,
17
2166
by: Jack | last post by:
For the structure below: struct A{ int a; double b; char c; }; struct A sa; printf("sizeof(A): %d\n", sizeof(sa));
15
3261
by: junky_fellow | last post by:
Hi, Is it possible to implement sizeof as a C function ?
6
13949
by: Angus | last post by:
On my PC (running Windows) if I ask for sizeof(TCHAR) I get 1 if UNICODE defined. Same if UNICODE (and _UNICODE) not defined. I sort of assumed that under UNICODE it would be 2? I understand on UNIX it is often 4. How can it be 1 for both ASCII AND Unicode? Confused
0
7666
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
8108
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7644
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
6260
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5484
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5213
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3626
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2083
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1201
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.