This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: pointers are not permitted as case values
>>>>> "Jakub" == Jakub Jelinek <jakub@redhat.com> writes:
Jakub> On Wed, Oct 02, 2002 at 11:41:55AM -0400, Jack Howarth wrote:
>> Hello, In rebuilding some srpms on ppclinux using gcc 3.2.1pre, I
>> noticed that hfsplusutils no longer builds. For the 1.0.4-4 srpm
>> of that package I now get...
>>
>> gcc -DHAVE_CONFIG_H -I. -I. -I.. -I../libhfsp/src -O2 -Wall -c
>> `test -f 'glob.c' || echo './'`glob.c glob.c: In function
>> `strmatch': glob.c:51: pointers are not permitted as case values
>> make[2]: *** [glob.o] Error 1
>>
>> which matches the code...
>>
>> static int strmatch(const char *str, const char *pat) { while (1)
>> { if (!*str && *pat && *pat != '*') return 0; // no more string
>> but still pattern
>>
>> switch (*pat) { case NULL: // pattern at end
Jakub> The warning is about the above line, you should write case 0:
Jakub> or case '\0': instead.
Some people define NULL simply as 0, which is sufficient and allows
that code to compile. Some people define NULL as (void *)0 which is
unnecessary but legal, and that's where this error comes from.
Perhaps one of the headers you're including switched from the short to
the verbose definition.
In any case, as a matter of style I would use NULL with pointers only,
and (explicitly written) 0 with non-pointers only. In your case, you
have a non-pointer, so "case 0" or better yet "case '\0'" is the right
answer, because the switch statement argument is a char.
paul