Earlier quoted context omitted.
Exactly so [0]. However, these days something or someone somewhere might object "to keep us safe from ourselves" Turbo-C used to check the zero location to see if it had changed and would issue a warning if so (in the real mode days). [0] My other computer is a PDP-11,
You say that as if that's a bad thing – I absolutely need to kept safe from myself, because I need all the help I need to make sure I'm doing things right!
*(char*)0 = 0; – What does the C++ programmer intend with this code? [video]
51–60 of 199 posts
Re: *(char*)0 = 0; – What does the C++ programmer intend with this code? [video]
#52Earlier 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]
#53Is it still a programming language, or is it already a riddle (like sudoku)?
Re: *(char*)0 = 0; – What does the C++ programmer intend with this code? [video]
#54Earlier quoted context omitted.
Not quite. (char *) 0 is the null pointer. The null pointer is not necessarily a binary all-zero. On some compilers in x86, the null pointer intentionally points to something which will cause a crash when written to.
Find me one contemporary example (ANSI C) with a disassembled screenshot. This is writing sizeof(char) (== 1 almost everywhere) zero to address zero. It is not using a NULL macro or other predefined symbol. In the real world, this would generally write a byte to address 0000:0000, leading to UB because it would fuck up the divide-by-zero IV. PS: I used Borland C++ 3.1, Microsoft C++ 3.x and 4.5x, Watcom, and early GN…
Re: *(char*)0 = 0; – What does the C++ programmer intend with this code? [video]
#55Earlier quoted context omitted.
Exactly so [0]. However, these days something or someone somewhere might object "to keep us safe from ourselves" Turbo-C used to check the zero location to see if it had changed and would issue a warning if so (in the real mode days). [0] My other computer is a PDP-11,
You say that as if that's a bad thing – I absolutely need to kept safe from myself, because I need all the help I need to make sure I'm doing things right!
Consider how a surgeon would respond if told not to use a scalpel because of the risk of accidental injury when using a sharp tool.
We learn from our mistakes - to which I'd add, sometimes we can afford to make mistakes (home programs) and other times we can't (safety-critical code).
Re: *(char*)0 = 0; – What does the C++ programmer intend with this code? [video]
#56Earlier quoted context omitted.
This is C code. Coder needs specifity hwo to align the char pointer to HW alignment expectations for memory address to prevent a segmentation fault.
0 is the only pointer value that's guaranteed to be aligned on all possible alignment boundaries, which is why it's so useful as a pointer in C.
Re: *(char*)0 = 0; – What does the C++ programmer intend with this code? [video]
#57Earlier quoted context omitted.
This is C code. Coder needs specifity hwo to align the char pointer to HW alignment expectations for memory address to prevent a segmentation fault.
0 is the only pointer value that's guaranteed to be aligned on all possible alignment boundaries, which is why it's so useful as a pointer in C.
Re: *(char*)0 = 0; – What does the C++ programmer intend with this code? [video]
#58Re: *(char*)0 = 0; – What does the C++ programmer intend with this code? [video]
#59Earlier quoted context omitted.
You say that as if that's a bad thing – I absolutely need to kept safe from myself, because I need all the help I need to make sure I'm doing things right!
I'd agree with that, to the extent that understanding how badly your tools can hurt you is an important thing to learn. Consider how a surgeon would respond if told not to use a scalpel because of the risk of accidental injury when using a sharp tool. We learn from our mistakes - to which I'd add, sometimes we can afford to make mistakes (home programs) and other times we can't (safety-critical code).
Re: *(char*)0 = 0; – What does the C++ programmer intend with this code? [video]
#60Earlier quoted context omitted.
Find me one contemporary example (ANSI C) with a disassembled screenshot. This is writing sizeof(char) (== 1 almost everywhere) zero to address zero. It is not using a NULL macro or other predefined symbol. In the real world, this would generally write a byte to address 0000:0000, leading to UB because it would fuck up the divide-by-zero IV. PS: I used Borland C++ 3.1, Microsoft C++ 3.x and 4.5x, Watcom, and early GN…
Regarding your PS, I used Borland's Turbo C++ 1.0, and I think you've forgotten that memory models existed. Honestly, that's a good nightmare to forget.