3 ms·
> NULL pointers will lead to a crash. Not in C. Dereferencing a NULL pointer is undefined behavior, so any of the actions described by the parent would be corr
by subleq 13y ago
> NULL pointers will lead to a crash.
Not in C. Dereferencing a NULL pointer is undefined behavior, so any of the actions described by the parent would be correct.
- gizmo686 13y agoIs 0 really the same thing the sane thing as 'NULL' in the context of C? If you actually wanted a pointer to the begging of the memory, you would dereference 0, which has the well defined meaning of getting whatever is at memory address 0. When the programming attempts to get that, it is shut down by the system.
- asveikau 13y ago> Is 0 really the same thing the sane thing as 'NULL' in the context of C? Yes. I don't have chapter and verse handy but it is in the standard. The bit pattern of NULL is not required to be zero (so memset(&p, 0, sizeof(p)) is not guaranteed to yield null) but it must compare equally to 0 and assigning 0 must produce NULL. [Edit: OK, in C99 this is covered in 6.3.2.3: Pointers. "An integer constant expression with the value 0, or such an expression cast to type void * , is called a null pointer constant." Then 7.17.3 says that NULL expands to a null pointer constant.] > If you actually wanted a pointer to the begging of the memory, you would dereference 0, Yeah, it's really easy to set up an environment where that happens. At one point I was experimenting with writing a small/toy kernel for x86 and I mapped the virtual address 0 to a valid page, and boom, dereferencing NULL did stuff. Not a great idea to set up the page tables that way for obvious reasons, but I'm going to guess that lots of hardware out there will let you do it... In the old days of 16-bit x86, linear address 0 had the interrupt vector, so as I recall lots of DOS (maybe even Win9x) environments had dereferencing NULL do meaningful (surely confusing) things.