2 ms·
It's true that in theory a NULL pointer could be 0xffffffff or such, and that would prevent some of the problems the article mentions. However, that would only
by azakai 8y ago
It's true that in theory a NULL pointer could be 0xffffffff or such, and that would prevent some of the problems the article mentions. However, that would only help when you assign NULL to a pointer explicitly. The problem is that in practice NULL pointers are often caused by other things, like thinking that zero-initialized memory contains a pointer - in fact, this is even more common in wasm than natively, since wasm guarantees memory and stack are initialized to zero.
This is serious enough an issue that for debugging purposes emscripten has a SAFE_HEAP mode which will check for NULL pointers on every access. We'd still need that to look for 0 even if the compiler considered NULL to be something other than 0.
- int_19h 8y ago> The problem is that in practice NULL pointers are often caused by other things, like thinking that zero-initialized memory contains a pointer Which, to be clear, is not a valid assumption wrt portable C or C++.
- spc476 8y agoWhile C may not mandate zero-initialized pointer is NULL, POSIX does.