Mail Archives: djgpp/1998/03/03/09:07:45
From: | mitch AT duzen DOT com DOT tr
|
Message-Id: | <199803031401.QAA26726@ankara.duzen.com.tr>
|
Organization: | User RFC 822- and 1123-compliant
|
To: | djgpp AT delorie DOT com
|
Date: | Tue, 3 Mar 1998 16:04:48 +0200
|
MIME-Version: | 1.0
|
Subject: | Re: int being 2 or 4 bytes long
|
In-reply-to: | <34F9E7A8.131D5B3E@alcyone.com>
|
On 1 Mar 98 Erik Max Francis was found to have commented thusly:
> Noam Rotem wrote:
>
> > Maybe it's trivial, but why is there a data type which its size can be
> > different in
> > different compilers? I refer to 'int'. Why can it be 2 or 4 bytes,
> > depending on the
> > implementation? What's the logic?
>
> The logic is that different compilers do things differently. In
> particular, the size of `int' is best left to the compiler because
> compilers will be able to do work in their native word size much faster
> than any other. So it makes sense to have `int' be this. If you have
> specific size requirements, use `short' or `long'. The limitations
> dictated by ANSI C are:
>
> 1. char must be at least 8 bits.
> 2. short must be at least 16 bits.
> 3. long must be at least 32 bits.
> 4. char must be no larger than short, which must be no larger than
> int, which must be no larger than long.
>
It is not so much the compiler that 'int' is designed for, but the
hardware. Compilers are designed to complement the CPU and its
interaction with memory addresses. Machines have the 'native word'
sizes and the compilers are just there as the go-between for machines
and the supposedly portable source code they are supposed to adapt.
I think it was on P. Hsieh's web page on optimization where I read
that it is often better to use 'int' than to use short or
char: even though int storage is the same or larger, there may be
extra instructions (from an assembly point of view) added to deal
with the data type conversions.
If you don't like this open-endedness in C, the Java advocates are
probably always happy to welcome a convert.
Mitch Halloran
Research (Bio)chemist
Duzen Laboratories Group
Ankara TURKEY
mitch AT duzen DOT com DOT tr
other job title: Sequoia's (dob 12-20-95) daddy
- Raw text -