The section C currently says:
"dereferencing the null pointer is a perfectly valid but typically unwanted action that may lead to undefined but non-crashing behavior in the application"
But the section "Dereferencing" currently says:
"In C, the behavior of dereferencing a null pointer is undefined"
These statements are not the same. I think the problem is in the first one, because it seems to assume that the "null pointer" is the same as the pointer to address zero. But I'm no expert, so I thought the proper action is to put it here.. — Preceding unsigned comment added by 185.147.13.130 (talk) 15:01, 7 May 2018 (UTC)
- Thank you for your note. You are right: the C standard does not say that the null pointer is the same as the pointer to address zero, and dereferencing the null pointer is always undefined behavior in C (and the implementation is allowed to assume that that any pointer that is dereferenced is not null). The section C is certainly misleading.
- I have tried to fix this. Is it better now? – Tea2min (talk) 07:10, 8 May 2018 (UTC)
- Thanks. But it still says "There are occasions when dereferencing the null pointer is intentional and well-defined", should that not be "There are occasions when dereferencing the pointer to address zero is intentional and well-defined"? Or am I not understanding the concept? 185.147.13.130 (talk) 09:36, 9 May 2018 (UTC)
- You are right. Feel free to fix that section. – Tea2min (talk) 09:54, 9 May 2018 (UTC)
- I did that! 185.147.13.130 (talk) 10:19, 9 May 2018 (UTC)
- What will happen if you will do this mmap( ( void *) 0, ( size_t ) 4096, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANON, -1, 0 ); 2A00:1370:812C:9562:3073:140:AA00:A551 (talk) 11:05, 4 May 2020 (UTC)
- Doesn't matter, the C standard still does not define it. Use
<code>your code here </code> next time you want to put code somewhere on Wikipedia. Please do not enter it into the article unless you find a citation for it. Holzklöppel (talk) 10:16, 20 August 2022 (UTC)
- WP talk pages are not a Q&A ... find somewhere else to ask your questions. Jibal (talk) 03:39, 11 March 2026 (UTC)
What the third paragraph of Null pointer § C says is
In practice, dereferencing a null pointer may result in an attempted read or write from memory that is not mapped, triggering a segmentation fault or memory access violation. This may manifest itself as a program crash, or be transformed into a software exception that can be caught by program code. There are, however, certain circumstances where this is not the case. For example, in x86 real mode, the address 0000:0000 is readable and also usually writable, and dereferencing a pointer to that address is a perfectly valid but typically unwanted action that may lead to undefined but non-crashing behavior in the application; if a null pointer is represented as a pointer to that address, dereferencing it will lead to that behavior. There are occasions when dereferencing a pointer to address zero is intentional and well-defined; for example, BIOS code written in C for 16-bit real-mode x86 devices may write the interrupt descriptor table (IDT) at physical address 0 of the machine by dereferencing a pointer with the same value as a null pointer for writing. It is also possible for the compiler to optimize away the null pointer dereference, avoiding a segmentation fault but causing other undesired behavior.[1]
so, if it used to claim that "dereferencing the null pointer is a perfectly valid but typically unwanted action that may lead to undefined but non-crashing behavior in the application", it no longer does so.
Instead, it notes that, on particular hardware configured in a particular fashion, accesses to a memory location with an address of 0 is a valid operation, and thus that, if a C implementation represents a null pointer as a pointer to address 0, if code built using that C implementation attempts to dereference a null pointer, that operation will load from, store into, or transfer program control to whatever relies at that location.
That does not mean that it's not an undefined operation in C, it just means that, under certain circumstances, it happens to make a valid memory reference rather than, for example, crashing. Guy Harris (talk) 16:50, 4 April 2026 (UTC)
- And as for the "what happens if..." question, if it was intended to ask whether that changes what the page should say, the answer is "no". That code won't work on many C platforms, as They. Are. Not. Unix-like. Systems. or are Unix-like systems but don't support
MAP_ANON, and, even on Unix-like systems that support MAP_ANON, what it does depends on whether the range of memory locations being mapped is already mapped or not. So, still undefined - the C specification doesn't specifically mention that possibility. Guy Harris (talk) 17:01, 4 April 2026 (UTC)