Mr. Grumpy :)
C has specific specifications for what is promoted when and how. They
are not ambiguous just not known by many.
I worked for a C compiler company so I'm may be a bit more familiar with
the actual C specs and how the compiler works.
However, I totally agree with you. I heavily typecast and parenthesize
my code to avoid any possible ambiguity. Sometimes for the compiler and
sometimes for someone else reading my code.
Mike
On 8/15/2024 6:09 PM, Fred Cisin via cctalk wrote:
On Thu, 15 Aug 2024, Paul Koning via cctalk wrote:
>> I don't know about the VAX,but my
gripe is the x86 and the 68000 don't
>> automaticaly promote smaller data types to larger ones. What little
>> programming I have done was in C never cared about that detail.
>> Now I can see way it is hard to generate good code in C when all the
>> CPU's are brain dead in that aspect.
It is not the hardware that is at fault.
If anybody else is to blame, it is the compiler.
int8 A = -1;
uint8 B = 255;
/* Those have the same bit pattern! */
int16 X;
int16 Y;
X = A;
Y = B;
will X and Y have a bit patterns of 0000 0000 1111 1111, or 1111 1111
1111 1111
If you expect them to be "promoted", you are giving ambiguous
instructions to the compiler.
The CPU isn't ever going to know.
THAT is why explicit typecasting is the way to go.
--
Grumpy Ol' Fred cisin(a)xenosoft.com