Bad optimisation with microcontroller compilers

V

Virchanza

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?
 
F

Francois Grieu

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
 
V

Virchanza

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. . .
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,073
Latest member
DarinCeden

Latest Threads

Top