NULL used in arithmetic warning not justified
robert.broussard@amd.com
robert.broussard@amd.com
Tue Jun 12 15:20:00 GMT 2001
I compiled the following sample code on both a Linux workstation (intel) and
a Sun workstation (sparc2) using gcc V2.95.2 and the command "gcc -Wall
sample.cpp".
Under linux, I get the following warning:
sample.cpp: In method 'bool CSomeClass::GetFnPtr(int)':
sample.cpp:12: warning: NULL used in arithmetic
gcc does not generate a warning when compiling the same code on a Sun.
I suspect the code is correct and that the Linux version of gcc is incorrect
in generating the warning. Nonetheless, the two implementations disagree
about the need for a warning.
sample.cpp:
----------------------------------------------------------------------------
--
#include <stdio.h>
#include <stdlib.h>
class CSomeClass;
typedef bool (CSomeClass::*PBOOLMEMBERFUNC)( int );
class CSomeClass
{
static PBOOLMEMBERFUNC S_FnPtrs[];
public:
bool GetFnPtr( int index ) { return( S_FnPtrs[index] != NULL ); }
// this is where the warning occurs
};
PBOOLMEMBERFUNC CSomeClass::S_FnPtrs[] = { NULL, &CSomeClass::GetFnPtr,
NULL, NULL, NULL };
int main()
{
CSomeClass someObject;
for( int i = 0; i < 5; i++ )
{
if( someObject.GetFnPtr( i ) )
printf( "Got It\n" );
else
printf( "Failed\n" );
}
return 0;
}
----------------------------------------------------------------------------
----
More information about the Gcc-bugs
mailing list