Skip to content

gcc/clang drop warning about comparison between pointer and zero character constant (pldstr.c:300:30) #3

Description

@GwynethLlewelyn

Hi there! I'm trying to compile ripOLE under Ubuntu 20.04.1 LTS. I have no problems with -Werror turned off, but it might be worth taking a look at that particular comparison:

GCC 9.3.0:

gcc -Wall -g -O2 -I. -Werror  -c pldstr.c
pldstr.c: In function ‘PLD_strtok’:
pldstr.c:300:30: error: comparison between pointer and zero character constant [-Werror=pointer-compare]
  300 |  if ((st->start)&&(st->start != '\0'))
      |                              ^~
pldstr.c:300:20: note: did you mean to dereference the pointer?
  300 |  if ((st->start)&&(st->start != '\0'))
      |                    ^
cc1: all warnings being treated as errors
make: *** [Makefile:7: pldstr.o] Error 1

Clang 10.0.0:

clang -Wall -g -O2 -I. -Werror  -c pldstr.c
pldstr.c:300:33: error: comparing a pointer to a null character constant; did you mean to compare to NULL? [-Werror,-Wpointer-compare]
        if ((st->start)&&(st->start != '\0'))
                                       ^~~~
                                       (void *)0
1 error generated.
make: *** [Makefile:7: pldstr.o] Error 1

Of course, you can always rewrite line 300 as:

if ((st->start)&&(*st->start != '\0'))

which is semantically more correct (I think... it's been many years since I last did some 'serious' work on C...), and similar to the code on line 286... but maybe it's not what's intended?

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions