Francois Grieu
7/18/2011 6:17:00 PM
On 2011/07/18 11:25, Virchanza wrote:
>
> When I'm writing an eternal loop in C, I always do:
>
> for (;;) { /* code */ }
>
> I've been using the PIC C compiler recently for PIC microcontrollers,
> and I've found out that it completely removes all loops from the
> program that begin with "for (;;)". I've had to change these eternal
> loops to:
>
> while (1) { /* code */ }
>
For what it's worth, I'm using MCC18 (Microchip PIC 18 C compiler)
and never noticed that.
At least in v3.38, "for (;;)" and "while (1)" seem just equivalent.
> Anyone else seen any other forms of bad optimisation with
> microcontroller compilers?
Yes, many. One example (with another compiler for the ST7M) is that
it generated nice-looking code for memcpy(dst,src,len) that copy
256 bytes instead of 0 when len is an unsigned char variable equal
to 0. The compiler vendor fixed it quickly.
Francois Grieu