delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1999/05/13/09:50:13

Date: Thu, 13 May 1999 16:48:31 +0300 (EET DST)
From: Pasi Franti <franti AT cs DOT joensuu DOT fi>
To: Eli Zaretskii <eliz AT is DOT elta DOT co DOT il>
cc: djgpp AT delorie DOT com, ageenko AT cs DOT joensuu DOT fi
Subject: Re: Portability and size_t type related question
In-Reply-To: <Pine.SUN.3.91.990513161150.12629R-100000@is>
Message-ID: <Pine.SOL.4.10.9905131626430.17043-100000@cs.joensuu.fi>
MIME-Version: 1.0
Reply-To: djgpp AT delorie DOT com
X-Mailing-List: djgpp AT delorie DOT com
X-Unsubscribes-To: listserv AT delorie DOT com

>>> typedef  unsigned short    U16;
>>> typedef  unsigned long     U32;
>>> typedef  unsigned char     BYTE;

> I understood that the above is for DJGPP, in which case it is
> correct.  As I said elsewhere in this thread, for any other
> environment, you indeed need to find out how many bits does each type
> use.

I just wanted to know the reasoning behind this solution. And yes, 
it is probably true for DJGPP as shown above. But in general, we aim
at portability beyond the DJGPP. No special needs currently but just
in case.

The second point I had for Eugene is that we already solved his
original problem long ago as he proposed the above solution to
be added our library. Our solution, as you might have guess,
uses any type, not EXACTLY 2 bytes, but AT LEAST two bytes,
and then use routines such as:

  WriteIntegerToFile(file,value,bytes)
  ReadIntegerFromFile(file,value,bytes)

This inputs/outputs the integer byte by byte, using the number
of bytes given the last parameter.

Another solution for making system-independent definition
for U32, for example, would be:

#include <limits.h>
#if (INT_MAX == 2147483647)
typedef int int32;
#elif (LONG_MAX == 2147483647)
typedef long int32;
#elif (SHRT_MAX == 2147483647)
typedef short int32;
#else
#error "No 32-bit type!"
#endif

Not very nice but should work in most cases.



- Raw text -


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