[Spread-users] The NULL/C++ bug

Andrew Barnert Andrew.Barnert at teneros.com
Tue Jun 13 16:14:31 EDT 2006


Over a month ago, I pointed out a bug in Spread 3.17.3 that prevents
using its C/C++ interface from C++ (or at least a conforming compiler
like gcc4 or VC8--it works in gcc2 and VC7): it tries to #define NULL as
(void *)0. I emailed a trivial patch to the list and to
spread at spread.org, and I've heard nothing from any of the maintainers. 

Is there any intention to fix it in a 3.17.4 (or 3.18 or 3.17.3.1 or
whatever) release? Is there even going to be another 3.x release? If we
have to maintain a patch locally, that's fine, but it'd be nice to know
that.

The obvious fix (as suggested by Neil Conway) is to #include <stddef.h>
at the top of sp_events.h instead of trying to #define NULL. 

This would be better than my patch, unless there's some good reason to
avoid this (e.g., Spread would otherwise compile with a freestanding
implementation on some embedded platform without standard headers). If
that's the case, here are some other possibilities that should work for
everything from ancient C compilers to modern C++ and C99 compilers:

* Replace NULL with 0 in the one or two places it appears
* Conditionally #define NULL as 0 for C++, (void *)0 for C 
  (as in the patch I submitted)
* #define and use SP_NULL instead of NULL
* Just assume that standard NULL is available so it'll be a 
  compiler error to #include sp_events.h without including the 
  standard headers first. 





More information about the Spread-users mailing list