3 ms·
> Null isn't zero ;) Actually, there were some systems where NULL /wasn't/ zero! On those systems, IIRC, your result could be different depending on how you in
by colejohnson66 10y ago
> Null isn't zero ;)
Actually, there were some systems where NULL /wasn't/ zero! On those systems, IIRC, your result could be different depending on how you interpret the bits:
// compares to NULL
// (not the macro, but the compiler constant; i.e. resigning NULL does nothing)
// (even if NULL isn't 0)
if (ptr == 0)
// compares to 0
if (reinterpret_cast<int>(ptr) == 0)
On x86 and ARM, those would both compare to 0 (don't get pedantic; NULL is 0 here), but on those old systems, the first one could be true, but not the second. Pretty weird.
http://stackoverflow.com/questions/2597142/when-was-the-null-macro-not-0 http://stackoverflow.com/questions/2597142/when-was-the-null...
- mirimir 10y agoI still think of null as undefined, which is very different from zero. When you average, for example, nulls are ignored. If you replace null with zero, you get incorrect averages.
- TorKlingberg 10y agocolejohnson66 was referring to NULL pointer in C, which you would never average. Are you thinking of NaN values in floating point?
- mirimir 10y agoWell, the parent article isn't about programming per se, but rather how to handle digital-mapping errors. My point is just that setting unknown or malformed values to zero may have unwanted effects. Although it's cute to point people to Null Island, or that farm in Kansas, maybe it's more useful to tell them that there's been an error.