4 ms·
While null should generally be conisdered harmful, initializing with arbitrary data is generally worse.
by Pxtl 10y ago
While null should generally be conisdered harmful, initializing with arbitrary data is generally worse.
- mirimir 10y agoNull isn't zero ;) What is the proper output for null?
- 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.
- tajen 10y agoIn Oracle, the empty string is null.
- Pxtl 10y agoWhich is infuriating when combined with ANSI NULL semantics. Empty string == empty string, you tool warehouses!
- colejohnson66 10y agoI remember hearing stories about how certain bugs would only show up in the release build, but not the debug build. After lots of debugging, they find out it's because the compiler initialized variables to 0 ("null") in debug mode, but not release mode.
- majewsky 10y agoClassical https://en.wikipedia.org/wiki/Heisenbug https://en.wikipedia.org/wiki/Heisenbug
- TorKlingberg 10y agoYes, that is quite common in embedded systems. In practice you often end up either: 1) Shipping the debug build, because it's been tested and it's fast enough anyway. 2) Always building the release build, because the debug build doesn't work. All those DEBUG_ASSERT's sit unused.