Forum: Compiler & IDEs Compilerwarnung: comparison is always true due to li


von Stephan (Gast)


Lesenswert?

Hallo zusammen

Beim Compilieren bekomme ich follgende Warnung:
avr-gcc -c -Os -save-temps -Wall -Wstrict-prototypes -fverbose-asm
-ffunction-sections -mcall-prologues -mmcu=at90s8515 -I. TAR.c -o
TAR.o
TAR.c: In function `main':
TAR.c:177: warning: comparison is always true due to limited range of
data type
avr-gcc -c -Os -save-temps -Wall -Wstrict-prototypes -fverbose-asm
-ffunction-sections -mcall-prologues -mmcu=at90s8515 -I. HD44780.c -o
HD44780.o
avr-gcc -c -Os -save-temps -Wall -Wstrict-prototypes -fverbose-asm
-ffunction-sections -mcall-prologues -mmcu=at90s8515 -I. misc.c -o
misc.o
avr-gcc -c -Os -save-temps -Wall -Wstrict-prototypes -fverbose-asm
-ffunction-sections -mcall-prologues -mmcu=at90s8515 -I. UART.c -o
UART.o
avr-gcc  HD44780.o misc.o UART.o TAR.o    -mmcu=at90s8515 -o TAR.elf
avr-objcopy -O avrobj -R .eeprom TAR.elf TAR.obj
avr-objcopy -O ihex   -R .eeprom TAR.elf TAR.rom
avr-objcopy -j .eeprom --set-section-flags=.eeprom="alloc,load"
--change-section-lma .eeprom=0 -O ihex   TAR.elf TAR.eep
avr-sizex --mcu at90s8515 TAR.elf

    Flash     SRAM     EEPROM
    -----     ----     ------
      58%      44%         0%

Errors: none
rm UART.o misc.o HD44780.o

In Zeile 177 steht die folgende Bedingung, contrast ist als unsigned
char definiert:
if((contrast < 30) && (contrast >= 0))
{
  contrast++;
  outp(contrast, OCR1AL);
}

Das komische daran ist jedoch, daß das Programm wie erwartet
funktioniert.
Ist die erklärbar?

MfG Stephan

von Uwe Nagel (Gast)


Lesenswert?

Hallo,

Du hast contrast als unsigned char definiert, also hat
es einen Wertebereich von 0 bis 255.
Deshalb ist der Ausdruck (contrast>=0) immer wahr, negative
Zahlen kann contrast ja nicht annehmen.

Uwe

von Stephan (Gast)


Lesenswert?

Hallo Uwe

Warum finde ich immer die einfachsten Fehler nicht.
An so etwas einfaches hätte ich jetzt nicht gedacht.
Vielen Dank.

Mfg Stephan

Bitte melde dich an um einen Beitrag zu schreiben. Anmeldung ist kostenlos und dauert nur eine Minute.
Bestehender Account
Schon ein Account bei Google/GoogleMail? Keine Anmeldung erforderlich!
Mit Google-Account einloggen
Noch kein Account? Hier anmelden.