Odd warning on wide char compare

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi All,

At the risk of looking dumb, I'm really stumped by a warning I see in a
simple testcase involving comparison of an unsigned int with >= L'\0'.

I see in wchar.h, that the wctob function has:

extern int __wctob_alias (wint_t __c) __asm ("wctob");
__extern_inline int
__NTH (wctob (wint_t __wc))
{ return (__builtin_constant_p (__wc) && __wc >= L'\0' && __wc <= L'\x7f'
	  ? (int) __wc : __wctob_alias (__wc)); }

When I build the simple test program below with the following command
line, I get a warning about the comparison.

[jwboyer@hansolo ~]$ gcc -W -Wall -Wno-unused-parameter -Wsign-compare -D__USE_EXTERN_INLINES -std=gnu99 --save-temps foo.c
foo.c: In function ‘foobar’:
foo.c:8: warning: comparison of unsigned expression >= 0 is always true
[jwboyer@hansolo ~]$

Looking at the foo.i file, I see that the wctob code is indeed present
yet it doesn't seem to produce a similar warning.  I tried playing around
with attributes and options, but I can't seem to make identical code in
the .c file not have that warning.

Given that wint_t is typedefed to unsigned int in wchar.h, I would have
expected a similar warning.  This happens with gcc 4.3.2 and gcc 4.4.
I'm fairly sure I'm missing something here so any help would be appreciated.

Thanks
josh

---

#include <stdlib.h>
#include <stdio.h>
#include <wchar.h>


extern __inline __attribute__ ((__gnu_inline__)) int
__attribute__ ((__nothrow__)) foobar(unsigned int baz)
{ return (__builtin_constant_p(baz) && baz >= L'\0' && baz <= L'\x7f'
		? (int) baz : 0); }

int main(int argc, char **argv)
{
	unsigned int bar = strtoul(argv[1], NULL, 0);

	/*if (foobar(bar)) */
		printf("size: %lu\n", sizeof(L'\0'));
		printf("value: %c\n", wctob(L'\0'));
		printf("size: %d\n", argc);
		printf("value: %u\n", bar);

	return 0;
}


[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux