delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2004/03/05/05:45:36

X-Authentication-Warning: delorie.com: mail set sender to djgpp-bounces using -f
From: "Tõnu Aas" <tonu AT ids DOT ee>
Newsgroups: comp.os.msdos.djgpp
References: <baec0bf0 DOT 0403012323 DOT 10896c3 AT posting DOT google DOT com> <esd840d8dde7matafu4vd11bsvagshadkl AT 4ax DOT com> <baec0bf0 DOT 0403020529 DOT 8f42598 AT posting DOT google DOT com> <Xk01c.25898$aZ3 DOT 23018 AT fed1read04> <4045a682$1 AT news DOT infonet DOT ee> <8d4d405go3mm3kvb70drkoat31ukdep52o AT 4ax DOT com> <404705d5$1 AT news DOT infonet DOT ee> <dn6f40ha2iqdibf6uldjgh3rsdkd2e4vvq AT 4ax DOT com>
Subject: Re: 16 bit integers
Date: Fri, 5 Mar 2004 11:03:29 +0200
Lines: 65
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
NNTP-Posting-Host: ids.ids.ee
Message-ID: <40485780$1@news.infonet.ee>
X-Trace: news.infonet.ee 1078482816 ids.ids.ee (5 Mar 2004 12:33:36 +0200)
Organization: INFONET.EE
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

> >> 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 -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019