Mail Archives: djgpp/2004/03/05/05:45:36
> >> Portable assumptions are: char holds at least 8 bits, int at least 16,
> >> long at least 32: pick the appropriate size for the range of integers
> >> you have to deal with. Avoid C99 stdint.h if you want to be portable
> >> to most existing implementations.
> Are you trying to imply the types defined in stdint.h are more
> portable than char, int, long?
Yes, because int and long are not portable. Even char can be not
portable.
You cant just write for(int i = 0; i < 66000; i++) isnt it ?
You cant even write for(int i = 0; i < 300; i++) in some case on embbeded
systems (o.k. thats another case).
Look around and you see that every library or package starts with
defining "their own types":
WORD u_int, int16 ...
And you are saying that you havent any trouble with using more than one
library because
they define basic types differently ?
> If you use the stdint.h definitions, maybe you should include the
> header with your code to ensure portability.
> That saves others the trouble of making up their own, or editing your
> types back to the base t0ypes.
The only thing they must do is to make stdint.h, what makes sense on their
plaform.
(if this platform doesnt have stdint.h) Thats all.
> Do you really see an advantage to using int_least16_t or int_fast32_t
> where int and long would do?
Not everybody writes "Hello world" type programs.
If you program must work on DOS, Windows, Linux and washing machine and
you must interfere with some harware or OS API, then you code will be full
of
int64_t, int16_t, uint8_t ...
> AFAICT stdint.h is intended for use in circumstances where particular
> integer characteristics are required for particular reasons in
> portable code.
> OTOH I expect most compilers to just treat them the same as the base
> types, so in that case what have you gained in terms of code clarity,
> efficiency, and portability?
??? If you see int16_t, then its clear, that 16 bit integer used.
If you see:
#if INT_MAX == 0x7fff
int offset;
#elif INT_MAX == 0x7fffffff
short int offset;
#endif
- is it clear for you ? Yes there are lots of librarys full of this type
"clarity".
Portability gained from using one and only header to gain portability.
Thing are even worse in C++ where 32 bit int is not the same as 32 bit long
int.
Tõnu.
- Raw text -