When using an unsigned char in a loop with limited range the variable is promoted to a 16 bit integer if the variable is passed to another function within the loop by value.
Tested using -Os on ATMEGA162: #include <avr/io.h> int sub2(uint8_t); int main(void) { static uint8_t x; volatile uint8_t y; while(1) { for(x=0;x<128; x++) { y+=sub2(x); } } return 0; } int sub2(uint8_t xyz) { volatile uint8_t abc; while(xyz < 64) { xyz++; abc+=xyz; } return abc; } -- Summary: Missed optimization using unsigned char loop variable Product: gcc Version: 4.1.2 Status: UNCONFIRMED Severity: enhancement Priority: P3 Component: c AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: henning dot m at insightbb dot com GCC build triplet: WinAVR 20070525 GCC target triplet: avr http://gcc.gnu.org/bugzilla/show_bug.cgi?id=33970