What header do I look at for...

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Jun 2008
Posts: 973
Reputation: Alex Edwards is a jewel in the rough Alex Edwards is a jewel in the rough Alex Edwards is a jewel in the rough Alex Edwards is a jewel in the rough 
Solved Threads: 107
Alex Edwards's Avatar
Alex Edwards Alex Edwards is offline Offline
Posting Shark

What header do I look at for...

 
0
  #1
Nov 21st, 2008
In C++, where are the header files that define the standard primitives and bitfields?

I would like to confirm something, if it is possible.

-Alex
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 7,681
Reputation: Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute 
Solved Threads: 727
Team Colleague
Narue's Avatar
Narue Narue is offline Offline
Code Goddess

Re: What header do I look at for...

 
1
  #2
Nov 21st, 2008
Primitives and bitfields are a part of the language, there's no header. Why don't you describe what you're trying to confirm instead of asking a vague question.
I'm here to prove you wrong.
Reply With Quote Quick reply to this message  
Join Date: Aug 2007
Posts: 1,678
Reputation: vmanes is a splendid one to behold vmanes is a splendid one to behold vmanes is a splendid one to behold vmanes is a splendid one to behold vmanes is a splendid one to behold vmanes is a splendid one to behold vmanes is a splendid one to behold 
Solved Threads: 193
vmanes's Avatar
vmanes vmanes is offline Offline
Posting Virtuoso

Re: What header do I look at for...

 
0
  #3
Nov 21st, 2008
Is <limits.h> what you're looking for?
Everyone's gotta believe in something. I believe I'll have another drink.
~~~~~~~~~~~~~~~~~~
Looking for an exciting graduate degree? Robotics and Intelligent Autonomous Systems (RIAS) at SDSM&T See the program brochure here.
Reply With Quote Quick reply to this message  
Join Date: Jun 2008
Posts: 973
Reputation: Alex Edwards is a jewel in the rough Alex Edwards is a jewel in the rough Alex Edwards is a jewel in the rough Alex Edwards is a jewel in the rough 
Solved Threads: 107
Alex Edwards's Avatar
Alex Edwards Alex Edwards is offline Offline
Posting Shark

Re: What header do I look at for...

 
0
  #4
Nov 21st, 2008
I'd like to know how the types are defined based on the platform.

I have heard that in C++ a char is always 1 byte and an integer is always 4 bytes on any machine, despite how many bits are available for an individual byte.

For example, a char can be measured as 1 byte even though its byte value is measured with 16 bits instead of 8, so I wanted to see how this is possible to better understand the situation...

I'm sorry if this sounds like a loose question, but its weird that 1 byte can still be 1 byte even if the type consists of 16 bits instead of 8 @_@.

I wanted to see if there was some header or implementation that defined the way bytes were mapped for each type >_<

-Alex
Last edited by Alex Edwards; Nov 21st, 2008 at 3:21 pm.
Reply With Quote Quick reply to this message  
Join Date: Aug 2007
Posts: 1,678
Reputation: vmanes is a splendid one to behold vmanes is a splendid one to behold vmanes is a splendid one to behold vmanes is a splendid one to behold vmanes is a splendid one to behold vmanes is a splendid one to behold vmanes is a splendid one to behold 
Solved Threads: 193
vmanes's Avatar
vmanes vmanes is offline Offline
Posting Virtuoso

Re: What header do I look at for...

 
0
  #5
Nov 21st, 2008
What you're asking about is defined (or not specifically defined) in the C++ standards. Size of an int should be the natural size of the achitecture - many of us grew up with 2-byte ints. The standards don't prescribe specifics, it's more on the order of any larger data type must be at least as large as that that comes before it. Thus, today you see that int and long int are generally the same size.

3.9.1 Fundamental types
1 Objects declared as characters (char) shall be large enough to store any member of the implementation’s basic character set. If a character from this set is stored in a character object, the integral value of that character object is equal to the value of the single character literal form of that character. It is implementation defined whether a char object can hold negative values. Characters can be explicitly declared unsigned or signed. Plain char, signed char, and unsigned char are three distinct types. A char, a signed char, and an unsigned char occupy the same amount of storage and have the same alignment requirements (3.9); that is, they have the same object representation. For character types, all bits of the object representation participate in the value representation. For unsigned character types, all possible bit patterns of the value representation represent numbers. These requirements do not hold for other types. In any particular implementation, a plain char object can take on either the same values as a signed char or an unsigned char; which one is implementation-defined.

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(39) ; the other signed integer types are provided to meet special needs.
__________________
39) that is, large enough to contain any value in the range of INT_MIN and INT_MAX, as defined in the header <climits>.
Everyone's gotta believe in something. I believe I'll have another drink.
~~~~~~~~~~~~~~~~~~
Looking for an exciting graduate degree? Robotics and Intelligent Autonomous Systems (RIAS) at SDSM&T See the program brochure here.
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 7,681
Reputation: Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute 
Solved Threads: 727
Team Colleague
Narue's Avatar
Narue Narue is offline Offline
Code Goddess

Re: What header do I look at for...

 
1
  #6
Nov 21st, 2008
>I have heard that in C++ a char is always 1 byte
Yes. Or to be more specific, "char" and "byte" are synonymous terms, and sizeof(char) is guaranteed to be 1.

>and an integer is always 4 bytes on any machine
Nope. The size of an integer is at least 16 bits, but it can be whatever the implementation chooses as long as the basic requirements for type relations are met.

>its weird that 1 byte can still be 1 byte even if
>the type consists of 16 bits instead of 8 @_@.
It's not weird at all when you understand that "byte" is an abstraction for the smallest addressable unit. An octet (the 8-bit entity you're familiar with) is one such concrete implementation of this abstraction.

>I wanted to see if there was some header or implementation
>that defined the way bytes were mapped for each type
The closest you can get is looking in <limits.h>. CHAR_BIT will tell you how many bits are in a byte, and the *MIN/*MAX values will give you an idea of how other types are structured on your system. You can find out the minimum requirements by looking at a suitable draft of the C standard. Example.
I'm here to prove you wrong.
Reply With Quote Quick reply to this message  
Join Date: Jun 2008
Posts: 973
Reputation: Alex Edwards is a jewel in the rough Alex Edwards is a jewel in the rough Alex Edwards is a jewel in the rough Alex Edwards is a jewel in the rough 
Solved Threads: 107
Alex Edwards's Avatar
Alex Edwards Alex Edwards is offline Offline
Posting Shark

Re: What header do I look at for...

 
0
  #7
Nov 21st, 2008
Originally Posted by vmanes View Post
What you're asking about is defined (or not specifically defined) in the C++ standards. Size of an int should be the natural size of the achitecture - many of us grew up with 2-byte ints. The standards don't prescribe specifics, it's more on the order of any larger data type must be at least as large as that that comes before it. Thus, today you see that int and long int are generally the same size.
Originally Posted by Narue View Post
>I have heard that in C++ a char is always 1 byte
Yes. Or to be more specific, "char" and "byte" are synonymous terms, and sizeof(char) is guaranteed to be 1.

>and an integer is always 4 bytes on any machine
Nope. The size of an integer is at least 16 bits, but it can be whatever the implementation chooses as long as the basic requirements for type relations are met.

>its weird that 1 byte can still be 1 byte even if
>the type consists of 16 bits instead of 8 @_@.
It's not weird at all when you understand that "byte" is an abstraction for the smallest addressable unit. An octet (the 8-bit entity you're familiar with) is one such concrete implementation of this abstraction.

>I wanted to see if there was some header or implementation
>that defined the way bytes were mapped for each type
The closest you can get is looking in <limits.h>. CHAR_BIT will tell you how many bits are in a byte, and the *MIN/*MAX values will give you an idea of how other types are structured on your system. You can find out the minimum requirements by looking at a suitable draft of the C standard. Example.

Ah... I think I'm understanding...

So basically, for an octet byte (8 bits) the table would look something like this...


constant integral types:

(using this list as an example)

-char (must be at least 1 byte)
-short (must be at least 1 byte but is typically 2 bytes)
-int (must be at least sizeof(short) bytes but is typically 4 bytes)
-long (must be at least sizeof(int) bytes but is typically 8 bytes)

Ah, so its no wonder int and long have the same range on some machines! O_O

If this is right, this clears some mist XD

Though I have yet to see a machine with a different bit-set that determines a byte. Sorry for my ignorance @_@.

I hope this is the right mindset for this #_#

-Alex
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 7,681
Reputation: Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute 
Solved Threads: 727
Team Colleague
Narue's Avatar
Narue Narue is offline Offline
Code Goddess

Re: What header do I look at for...

 
1
  #8
Nov 21st, 2008
>Though I have yet to see a machine with
>a different bit-set that determines a byte.
If your work is primarily on workstations, you aren't likely to. DSPs are a common example where CHAR_BIT varies away from 8.
I'm here to prove you wrong.
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 960
Reputation: MosaicFuneral is just really nice MosaicFuneral is just really nice MosaicFuneral is just really nice MosaicFuneral is just really nice MosaicFuneral is just really nice 
Solved Threads: 92
MosaicFuneral's Avatar
MosaicFuneral MosaicFuneral is offline Offline
Posting Shark

Re: What header do I look at for...

 
0
  #9
Nov 21st, 2008
Yes, there really is a need for standardization large data-types. Some of them can very greatly(like long double ) from compiler-to-compiler.

Page 6. here:
http://www.agner.org/optimize/calling_conventions.pdf
Last edited by MosaicFuneral; Nov 21st, 2008 at 5:45 pm.
"Jedenfalls bin ich überzeugt, daß der Alte nicht würfelt."
"I became very sensitive to what will happen to all this and all of us." -Two geniuses named Albert
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 2,001
Reputation: ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of 
Solved Threads: 343
ArkM's Avatar
ArkM ArkM is offline Offline
Postaholic

Re: What header do I look at for...

 
0
  #10
Nov 22nd, 2008
Suppose one fine day (in year 1990, for example) the C++ Standard defines native binary data representations. Do you want 16-bit int now? How many long long longs are you ready to add in the future?

An experienced and far-sighted software architect never relies on external data binary interfaces. There are lots of methods to cope with binary data incompatibilities.

If you want fixed and standardized data types representations, switch to Java. Then try to implement useful soft for PIC or TI microcontrollers in Java ...
Last edited by ArkM; Nov 22nd, 2008 at 3:07 am.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC