develooper Front page | perl.perl5.porters | Postings from April 2006

[PATCH] reduce gcc -ansi -pedantic noise plus a suggestion

Thread Next
Jarkko Hietaniemi
April 28, 2006 12:57
[PATCH] reduce gcc -ansi -pedantic noise plus a suggestion
Message ID:
Background: mixing signed and unsigned character pointers is
a dubious practice (mainly, I think, because of the uncertainty
of a "char" being of unknown signedness), but unfortunately the
most common C compiler, gcc, doesn't give a warning about such
mixing, not by default or with -Wall.  gcc does, however, warn
about that given the options -ansi -pedantic.

Therefore, I suggest that at least some perl5-porters and/or
smoke testers could perhaps start using the Configure option
-Dgccansipedantic, which adds the options -ansi -pedantic in
the platforms where that is known to work (i.e. not to cause
havoc with system headers, e.g. in Solaris at least in the past
the -ansi could not be used).  This way there is at least more
chance of the "mixed-sign-pointer" warning seen by more people
and being fixed faster.  The error is e.g.

ptr.c:3: warning: pointer targets in initialization differ in signedness

I also would add -Wpointer-arith to stop gcc silently making up
sizeof(void) == 1:

ptr.c:4: warning: invalid application of `sizeof' to a void type

The attached patch cleans up blead enough so that -ansi -pedantic
doesn't scream too much.  98% of the warnings were caused by the
printf format "%p" aka SVf being used to print a mixed bag of pointers.
This, however, cannot be done (or, at least, this is what gcc -ansi
-pedantic thinks), but instead only (void*) can be used as the argument
to "%p".  Ergo, few dozen (void*) casts in the SVf cases added.

In perl.h I think I found a real bug related to the use of -ansi
-pedantic.  Namely, the -ansi -pedantic nixes the use of the gcc
extension "brace groups" (which Perl uses for STMT_START and
STMT_END in gcc).  The cflags and perl.h tried to organize so that
the use of -ansi -pedantic disables the use of the brace groups --
but this didn't seem to work, because perl.h tested for -ansi AND
-pedantic while it seems it's only the -pedantic that doesn't like
the brace groups.

Note that the -ansi -pedantic cannot be made the defaults, though,
too many platforms and most importantly XS compilation would go boom.
(And it would disable the "brace groups".)

Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About