Earlier quoted context omitted.
On ATmega processors, the register file is mapped to 0, so this would be writing 0 to r0.. which GCC reserves as a dedicated 0 register anyway.
The PDP-10 did that. There was actually core memory at addresses 0-15 but if you had registers they overlaid that. Yes, I said if you had registers--if you were cheap you could buy your PDP-10 without registers and all the instructions that referenced registers would use core instead. Since the registers were in effect just 16 words of fast semiconductor memory overlaying the first 16 words of slow core memory you co…
*(char*)0 = 0; – What does the C++ programmer intend with this code? [video]
81–90 of 199 posts
Re: *(char*)0 = 0; – What does the C++ programmer intend with this code? [video]
#82Not a big fan of the format of the talk. The guy is a good orator, but it takes ages to go to the point. A bit annoying if you're actually interested in the technical part rather than the jokes.
Re: *(char*)0 = 0; – What does the C++ programmer intend with this code? [video]
#83Old school comment... back in the day, there were computers on which dereferencing the null pointer would in fact return zero. And given that a typical linked list is terminated by a null, mistakes could creep in where "points to a 0" was checked when "pointer is 0" should have been. Needless to say, code like this would crash in mysterious ways when compiled on a machine where location 0, while readable, had nonzero…
Re: *(char*)0 = 0; – What does the C++ programmer intend with this code? [video]
#84Earlier quoted context omitted.
Not quite, I think. Since this is a char pointer being used, only the first byte of the interrupt address would be zeroed. Since in real mode those are far pointers, the lower byte of the segment would be zeroed. So xx00:xxxx. But yes, the interrupt table was my first thought when reading the headline.
Char can be the same size as short or int. You can't assume it is one byte.
A byte is CHAR_BIT bits, where CHAR_BIT >= 8. (It's exactly 8 on most implementations; DSPs are the most common exception).
short and int are both required to be at least 16 bits wide. It's possible for int to be 1 byte (sizeof (int) == 1), but only if CHAR_BIT >= 16.
Re: *(char*)0 = 0; – What does the C++ programmer intend with this code? [video]
#85Earlier quoted context omitted.
If I'm understanding what you're saying correctly, the memory location with address 0 is actually a writable address, but with the value being used semantically to handle division by zero? It's kind of wild to me that would even something that's even allowed to be done manually, let alone required by a certain mode. Is this something provided for compatibility reasons that you'd have to opt into, or is it just someth…
Back in the day there were no protections. You could write to any address whether it was used by the CPU for interrupt vectors, part of the OS, hardware addresses, anything.
Re: *(char*)0 = 0; – What does the C++ programmer intend with this code? [video]
#86Not a big fan of the format of the talk. The guy is a good orator, but it takes ages to go to the point. A bit annoying if you're actually interested in the technical part rather than the jokes.
If you use GPT-4 with Browsing turned on and supply it with the title, it will find the page and use the transcript and you can ask it questions. Then you can look at the transcripts to find the spots and verify. Alternatively, if you have an AI-enabled browser you can ask it about the transcript once you open it.
Re: *(char*)0 = 0; – What does the C++ programmer intend with this code? [video]
#87Earlier quoted context omitted.
I’m glad you appreciated me saying exactly this in the talk
Ah fuck, I grepped the YouTube transcript for WASM/WebAssembly but I guess youtube's automatic captions aren't very good. I feel silly now for not watching the video before commenting.
Re: *(char*)0 = 0; – What does the C++ programmer intend with this code? [video]
#88Re: *(char*)0 = 0; – What does the C++ programmer intend with this code? [video]
#89Old school comment... back in the day, there were computers on which dereferencing the null pointer would in fact return zero. And given that a typical linked list is terminated by a null, mistakes could creep in where "points to a 0" was checked when "pointer is 0" should have been. Needless to say, code like this would crash in mysterious ways when compiled on a machine where location 0, while readable, had nonzero…
IBM AIX is a Unix-like system on which dereferencing a null pointer for a read is guaranteed to return zero. But writes will crash. It’s pretty weird.
https://docstore.mik.ua/manuals/hp-ux/en/B2355-60130/chatr_p...
Wonderful fun when they shipped a Kerberos library that unconditionally dereferenced a potentially null optional pointer-to-struct, relying on the executable to be set in the “null tolerant” mode!
Re: *(char*)0 = 0; – What does the C++ programmer intend with this code? [video]
#90Seg fault!