Hi everyone
Where can I find a list of portable declarations for ints and floats?
Printable View
Hi everyone
Where can I find a list of portable declarations for ints and floats?
What's a portable declaration?
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.
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. :D
stdint.h has a list of types such as int32_t, but again isn't completely portable.
Cool, I missed that. Though it seems that, in C99:
Quote:
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.
Itsme86 wrote:
What indication do you have that the declarations as given by stdint.h wont beQuote:
stdint.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.
Thanks all