I can't say why the compiler has thrown out their bodies (I haven't looked at the code that closely), but the "while" loops in both functions will never exit. Since you have declared "icnt" as unsigned, "icnt + 1" will always be true. I'm surprised the the compiler didn't issue a warning along these lines. What warning level are you compiling with? - Carl
On Sun, Oct 4, 2009 at 12:33 PM, Vaclav Peroutka <vacla...@seznam.cz> wrote: > Hello all, > > I am sorry, but maybe somebody has expierience why the following code is > deleted during optimization. I have two functions for printing of numbers > (uart_puts() just send string to UART) : > void uart_putux( unsigned int aInt) > { > unsigned char buf[5]; > unsigned char icnt = 4; > > buf[icnt--] = 0x00; > while(icnt+1) { > buf[icnt] = (aInt&0x0f) + 0x30; > if (buf[icnt] > 0x39) { > buf[icnt] += 0x07; > } > aInt >>= 4; > icnt--; > } > uart_puts( buf); > } > > void uart_putlx( unsigned long aInt) > { > unsigned char buf[9]; > unsigned char icnt = 8; > > buf[icnt--] = 0x00; > while(icnt+1) { > buf[icnt] = (aInt&0x0f) + 0x30; > if (buf[icnt] > 0x39) { > buf[icnt] += 0x07; > } > aInt >>= 4; > icnt--; > } > uart_puts( buf); > } > > After I compile and link the code, in .LST I see following: > void uart_putux( unsigned int aInt) > { > 35a: ff cf rjmp .-2 ; 0x35a <uart_putux> > > 0000035c <uart_putlx>: > } > uart_puts( buf); > } > > void uart_putlx( unsigned long aInt) > { > 35c: ff cf rjmp .-2 ; 0x35c <uart_putlx> > > For compilation I use following: > /opt/avr-gcc.4.3.4/bin/avr-gcc -g -mmcu=atmega16 -Wall -Wstrict-prototypes > -Os -mcall-prologues -I /opt/avr-gcc.4.3.4/bin/include > -fno-inline-small-functions -fno-reorder-blocks > -fno-reorder-blocks-and-partition -fno-reorder-functions > -fno-toplevel-reorder -fno-move-loop-invariants -c -o hal.o hal.c > > If I remove "-Os", the code is there. But if I understand correctly, gcc > sees the code unusable. What is bad inside ? The code worked in older > avr-gcc... > > Thank you for help, > Vaclav > > > _______________________________________________ > AVR-GCC-list mailing list > AVR-GCC-list@nongnu.org > http://lists.nongnu.org/mailman/listinfo/avr-gcc-list >
_______________________________________________ AVR-GCC-list mailing list AVR-GCC-list@nongnu.org http://lists.nongnu.org/mailman/listinfo/avr-gcc-list