Subject: RFC: GCC should warn when evaluating a pointer return type from
a function used in a conditional that performs arithmetic with it
Shouldn't GCC generate some form of warning with the following code, for
the "if(foobar(i) < 0)" statement ?
It does generate a warning if you use "int j = foobar(i);"
I would think this sort of error should be a default warning (i.e. not
need to specifying any additional -W option) and it should certainly be
caught when specifying "-Wall".
Tried with:
gcc version 3.4.2 20041017 (Red Hat 3.4.2-6.fc3)
gcc version 4.0.2 20051125 (Red Hat 4.0.2-8)
gcc version 4.2.1
I don't think MSVC warns but SunPro C compiler (with Solaris 10 / Sun
Studio 12) does.
Request for comments,
Darryl
#include <stdio.h>
extern char *foobar(int a);
char *
foobar(int a)
{
static char buf[128+1];
sprintf(buf, "%d", a);
return buf;
}
int
main(int argc, char *argv[])
{
char *cp;
int i;
i = 42;
/* vvv SHOULDNT THIS GENERATE SOME FORM OF WARNING ??? */
if(foobar(i) < 0) {
printf("TRUE\n");
} else {
printf("FALSE\n");
}
return 0;
}