avr-gcc-list
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [avr-gcc-list] Multiply is broken on Mega128


From: Larry Barello
Subject: Re: [avr-gcc-list] Multiply is broken on Mega128
Date: Wed, 29 Jan 2003 18:37:35 -0800

This brings up a question I have about casting & type.  Normally I
expect the compiler to do the right thing.  However I too have found
my self spending inordinate amounts of time getting the casting &
grouping right to preserve accuracy, etc.  Usually I need to resort to
the assembly listing to figure out when the casting is correct.
Obviously my mental model of how the compiler works is wrong.

So, why did the code, below, need the cast?  Shouldn't the compiler
promote everything to long since the destination was long?   Or was
the compiler promoting the char to an int, which overflowed, before
promoting to a long?

Is there a write up, somewhere, on how C evaluates expressions and
how it deals with promoting different word sizes?

Cheers!

----- Original Message -----
From: "Volkmar Dierkes" <address@hidden>


> Mike,
>
> it works, if you use correct type conversion.
>
> Your code:
> > for (i=0; i < T8x16SIZE; i++)
> > {
> > x = t8x16[i].a * t8x16[i].b;
> > y = t8x16[i].x;
>
> Better:
> > x = (int32_t) t8x16[i].a * t8x16[i].b;
> > y = t8x16[i].x;
>

avr-gcc-list at http://avr1.org



reply via email to

[Prev in Thread] Current Thread [Next in Thread]