This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c/16159] New: In GCC value in comparison compared as signed not unsigned


Windows XP
avr-gcc (GCC) 3.3.2
Copyright (C) 2003 Free Software Foundation, Inc.
May be related to bug 11492 gpp.

Compiling: bugcheck.c
avr-gcc -c -mmcu=atmega16 -I. -g   -O0 -funsigned-char -funsigned-bitfields -
fpack-struct -fshort-enums -Wall -Wstrict-prototypes -Wa,-
adhlns=bugcheck.lst  -std=gnu99 -Wp,-M,-MP,-MT,bugcheck.o,-
MF,.dep/bugcheck.o.d bugcheck.c -o bugcheck.o 
bugcheck.c: In function `main':
bugcheck.c:6: warning: unused variable `d'

Linking: bugcheck.elf
avr-gcc -mmcu=atmega16 -I. -g   -O0 -funsigned-char -funsigned-bitfields -
fpack-struct -fshort-enums -Wall -Wstrict-prototypes -Wa,-adhlns=bugcheck.o  -
std=gnu99 -Wp,-M,-MP,-MT,bugcheck.o,-MF,.dep/bugcheck.elf.d bugcheck.o   --
output bugcheck.elf -Wl,-Map=bugcheck.map,--cref    -lm



If the unsigned char is made unsigned int the proper comparisons are made.

volatile unsigned char a,b;
int main(void)
{
  volatile int loops=0;
	unsigned char d,c=6;
	a=126;
	b=130;
	
	
	while( (b-a)<c)// (b-a) appears to be promoted to int ??
	{
		loops++;
		a++;
	}
	// Loops is now=130
	a=126;
	loops=0;
	while ( (unsigned char)(b-a)<c )// This is a work around
	{
		loops++;
		a++;
	}
	// Loops is now=5
	return a*loops;
}

-- 
           Summary: In GCC value in comparison compared as signed not
                    unsigned
           Product: gcc
           Version: 3.3.2
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: c
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: stephenmsimmons at yahoo dot com
                CC: gcc-bugs at gcc dot gnu dot org


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=16159


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]