News for hackers. Stuff that matters.
Re:*(char*)0 = 0; - What Does the C++ Programmer Intend with... by layer8 on Tuesday October 17, 2023 @03:52PM (#37920647)
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.

Re:*(char*)0 = 0; - What Does the C++ Programmer Intend with... by kevin_thibedeau on Tuesday October 17, 2023 @08:07PM (#37923273)
Char can be the same size as short or int. You can't assume it is one byte.
Re:*(char*)0 = 0; - What Does the C++ Programmer Intend with... by _kst_ on Tuesday October 17, 2023 @09:02PM (#37923675)
You can't assume char is one octet. It is one byte by definition.

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... by _kst_ on Wednesday October 18, 2023 @01:27AM (#37925115)
A clarification: You can certainly assume that char is 8 bits if you don't mind losing portability to a small minority of systems.

If I'm being pedantic, I might add something like

    #if CHAR_BIT != 8
    #error "This code assumes 8-bit char"
    #endif
But realistically, if I'm using headers defined by either POSIX or Windows, that's probably enough of a guarantee. (Though I'd still use CHAR_BIT rather than 8 to refer to the number of bits in a byte.)
Re:*(char*)0 = 0; - What Does the C++ Programmer Intend with... by gpderetta on Wednesday October 18, 2023 @07:17AM (#37927137)
posix indeed guarantees CHAR_BIT == 8.
Re:*(char*)0 = 0; - What Does the C++ Programmer Intend with... by layer8 on Tuesday October 17, 2023 @10:25PM (#37924220)
Yeah, if you're going to be pedantic, check your facts, see the sibling. Since I'm assuming an 8086 interrupt table, I'm also going to assume 8-bit chars, as that's the x86 addressing model. And dereferencing a null pointer is UB, so you can't count on anything anyway without making further assumptions.