Re: 16-bit int

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 11/08/2012 12:47, Vincent Lefevre wrote:
On 2012-08-10 09:05:13 +0000, Göran Steen wrote:
Any C99 compiler - and almost all pre-C99 compilers - will have
<stdint.h>. I don't know of any compiler less than 15 years old that
doesn't come with a <stdint.h>, and many people using such compilers
have written their own <stdint.h>.

I thought that Microsoft's compiler didn't have <stdint.h>.
I've also heard that <inttypes.h> is more common.

The int_fast16_t and int_fast32_t types (and the unsigned versions)
are mandatory in <stdint.h>, so you can take it for granted that
/all/ compilers support them. This is unlike the fixed-size types
(like int16_t) that will be defined if and only if the target
supports types of exactly that size (some architectures don't
support the smaller types).

But int_fast16_t is useless to test whether code can be affected
by 16-bit truncation on platforms for which int_fast16_t is really
a 16-bit type. For tests, int16_t is necessary. Now the user may
want to know what targets provide this type.


The use of "int_fast16_t" was to get correct and optimal code, whether the target is 16-bit or 32-bit. You are right that this will not test whether the code will work on 16-bit targets if it is compiled on a 32-bit target - using int16_t will help more for that (but it won't give guarantees, unless you are absolutely sure there are no hidden int promotions).




[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux