[Top][All Lists]

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

Re: [avr-gcc-list] Got strange compilation problem

From: Joerg Wunsch
Subject: Re: [avr-gcc-list] Got strange compilation problem
Date: Thu, 16 Feb 2006 10:48:57 +0100 (MET)

"David Bourgeois" <address@hidden> wrote:

(A full compilable example would be nice.  It's always hard to guess
the various missing pieces when trying to reproduce other people's

> Replacing the 2 lines
>      length = (p->inIdx) - (p->outIdx);
>      length %= FIFO_SIZE;
> by
>      length = (((p->inIdx) - (p->outIdx)) % FIFO_SIZE);
> completely broke my code.

The difference between both is that in the first case, the entire
computation is trimmed down to a uint8_t result immediately, while in
the second case, the intermediate results are computed as `int'.  Note
the change in signedness: the implicit promotion of a uint8_t argument
to an int expression makes the expression signed.  I guess that's what
broke your code.

The IMHO equivalent single-line expression would be

length = (uint8_t)(unsigned)((p->inIdx) - (p->outIdx)) / FIFO_SIZE;

even though GCC still generates somewhat different code for that.

J"org Wunsch                                           Unix support engineer
address@hidden        http://www.interface-systems.de/~j/

reply via email to

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