On 7-1-2012 20:54, Jon Cruz wrote:
On Jan 7, 2012, at 11:39 AM, Tomaz Canabrava wrote:
Stroustrup answer to that:
Should I use NULL or 0?
In C++, the definition of NULL is 0, so there is only an aesthetic difference. I prefer to avoid macros, so I use 0. Another problem with NULL is that people sometimes mistakenly believe that it is different from 0 and/or not an integer.
Actually, for a modern compiler NULL is not an integer.
C++ did a bit of a change, and 0 gained special meaning. I believe that most of the systems where it made an actual difference are now gone, but it did.
However... the main reason I made the code change is that when I updated to gcc 4.5.2, it started warning on that constructor. It complained that we were setting a pointer value into a non-pointer variable.
So we probably have NULL defined as some pointerish macro or value and which should not be assigned to integer variables, while '0' is a magical constant that the compiler knows to just do the right thing with for both pointers and integers. '0' by the C++ language definition works in all cases, but NULL does not.
This and the associated warning start to become very important for 64-bit code. Mixing integers and pointers leads to major problems.
Bottom line, though, is that we need to remove warnings by fixing the code. The pointer assignments in that initializer could be changed to "NULL", but the integer ones need to stay changed to zero.
Of course the int should be initialized with '0', but pointers should be with 'NULL'. The code was wrong indeed, and was fixed. But it created some other 'wrongness' that heavily annoyed me. (and because I remembered some talk about 0 vs. NULL before, I decided to kill it now so it doesn't spread) Fixed in r10859.
I think _verb_t should be initialized with SP_VERB_INVALID. However, the verb enumeration does not set SP_VERB_INVALID explicitly to 0. But perhaps someone with more knowledge of the swatch code can have a more detailed look at it. For example, line 180 looks like it should also include a test for _verb_t != SP_VERB_INVALID.
Thanks, Johan