www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1999/05/12/10:11:07

Date: Wed, 12 May 1999 17:07:25 +0300 (IDT)
From: Eli Zaretskii <eliz AT is DOT elta DOT co DOT il>
X-Sender: eliz AT is
To: Eugene Ageenko <ageson AT cs DOT joensuu DOT fi>
cc: djgpp AT delorie DOT com
Subject: Re: Portability and size_t type related question
In-Reply-To: <373985AA.EF8D47D5@cs.joensuu.fi>
Message-ID: <Pine.SUN.3.91.990512170330.17607E-100000@is>
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

On Wed, 12 May 1999, Eugene Ageenko wrote:

> Q1. Is there any way in C to specify the integer type for variable and
> to be sure that this type is exactly 4 bytes long.

No.  You need to write a small test program for that.

> Like 'char' is always 1 byte.

That's not true, either.  There are compilers (mostly for embedded 
systems) where `char' is 32-bit wide.

> It is because 'int' is depending on the system, and I have to be sure
> I am writing/reading 4 bytes (ot let's say the SAME amount of bytes
> to/from file). This is for portability.

The usual way is to use a typedef, like "int_32", and have the typedef 
change on each supported system as necessary.

> Q2. More complicated question: the type 'size_t'.

Why is this a different question?  The answer is the same as Q1.

> Actually I wish to use some type which is of the constant length and
> wanna be sure it will be portable.

This isn't possible with the current C standards.

- Raw text -


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