This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

NULL used in arithmetic warning not justified


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;
}
----------------------------------------------------------------------------
----


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]