Mail Archives: djgpp/1999/05/12/10:11:07
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 -