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

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

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


From: Lars Noschinski
Subject: Re: [avr-gcc-list] Got strange compilation problem
Date: Thu, 16 Feb 2006 11:32:14 +0100
User-agent: mutt-ng devel (Linux)

* David Bourgeois <address@hidden> [2006-02-16 11:17]:
Replacing the 2 lines
    length = (p->inIdx) - (p->outIdx);
    length %= FIFO_SIZE;
by
    length = (((p->inIdx) - (p->outIdx)) % FIFO_SIZE);

completely broke my code. I'm using avr-gcc 3.4.5 (latest winavr release) under avrstudio, -Os.
[...]
Here, the problem occurs when p->inIdx) - (p->outIdx) is <0, then the modulus is not done, the return value is 0xF9 for example.

"%" is a signed modulus, so -1 % 8 == -1. Try

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

to force the difference to be a positive. Which types do inIdx and
outIdx have?




reply via email to

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