Bad optimisation with microcontroller compilers

  • Follow


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 */ }

Anyone else seen any other forms of bad optimisation with
microcontroller compilers?
0
Reply virtual (44) 7/18/2011 9:25:54 AM

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 */ }
> 
> Anyone else seen any other forms of bad optimisation with
> microcontroller compilers?

I've always found programming in PIC assembly language
to be too easy 
to allow me to think of programming them in C.

-- 
pete
0
Reply pfiland (6613) 7/18/2011 11:00:52 AM


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
0
Reply fgrieu (251) 7/18/2011 6:17:18 PM

On Jul 18, 7:17=A0pm, Francois Grieu <fgr...@gmail.com> wrote:

> Yes, many. One example (with another compiler for the ST7M) is that
> it generated nice-looking code for =A0memcpy(dst,src,len) =A0that copy
> 256 bytes instead of 0 when len is =A0an unsigned char variable equal
> to 0. The compiler vendor fixed it quickly.
>
> =A0 =A0Francois Grieu


I posted about the for(;;) problem over on the Microchip forums. Let's
see if they change the compiler behaviour. . .
0
Reply virtual (44) 7/18/2011 8:45:31 PM

3 Replies
45 Views

(page loaded in 0.076 seconds)


Reply: