Hi everyone
Where can I find a list of portable declarations for ints and floats?
Hi everyone
Where can I find a list of portable declarations for ints and floats?
Some compliers, I am told, regard an int as 16 bits others as 32 bits. There are portable
means of declaring variables and I can't recall what they are (haven't been C coding for a while).
I do not think there is such a list. There are minimum sizes specified, but even for char the size in terms of bits is not fixed other than for the minimum. Still, you could use sizeof and CHAR_BIT to find out.
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)
The stuff in limits.h will tell you what your compiler supports in terms of maximum and minimum values, but most of the time you don't have to worry about how many bits a type has. For example, if you need more than 32,767 or less than -32,767, use a long int instead of an int because it has a guaranteed minimum of 32 bits and an int only has a minimum of 16 bits. If you have to know how many bits a type has, you probably need to be using an array of char because your stuff is really low level.
Some compilers support portable types like int32 and int16, but ironically, they're not portable.
stdint.h has a list of types such as int32_t, but again isn't completely portable.
If you understand what you're doing, you're not learning anything.
Cool, I missed that. Though it seems that, in C99:
These types (Exact-width integer types) are optional. However, if an implementation provides integer types with widths of 8, 16, 32, or 64 bits, it shall define the corresponding typedef names.
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)
dwk
Seek and ye shall find. quaere et invenies.
"Simplicity does not precede complexity, but follows it." -- Alan Perlis
"Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
"The only real mistake is the one from which we learn nothing." -- John Powell
Other boards: DaniWeb, TPS
Unofficial Wiki FAQ: cpwiki.sf.net
My website: http://dwks.theprogrammingsite.com/
Projects: codeform, xuni, atlantis, nort, etc.
Itsme86 wrote:
What indication do you have that the declarations as given by stdint.h wont bestdint.h has a list of types such as int32_t, but again isn't completely portable.
completely portable?
Thanks
Did you even read laserlight's reply? Why bother making a thread if you won't read what people write in it?
Quzah.
Hope is the first step on the road to disappointment.
Thanks all
The number of assertions that can not be disproven are only limited by one's imagination.