[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.c

Bad optimisation with microcontroller compilers

Virchanza

7/18/2011 9:26:00 AM


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?
3 Answers

pete

7/18/2011 11:01:00 AM

0

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

Francois Grieu

7/18/2011 6:17:00 PM

0

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

Virchanza

7/18/2011 8:46:00 PM

0

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

> 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


I posted about the for(;;) problem over on the Microchip forums. Let's
see if they change the compiler behaviour. . .