4 ms·
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.
by sargstuff 3y ago
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.
- kps 3y ago0 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.
- AlotOfReading 3y agoChar pointers have alignment 1 on any conforming implementation and all pointers are aligned at 0. The code will write to "address 0", assuming the compiler hasn't freaked out because (char*)0 is the char null pointer and thus undefined behavior to access. Note the additional caveat that address 0 may not be the first 8 bits of mapped memory (which isn't necessarily addressable).
- deleted 3y ago[deleted]
- sargstuff 3y agoThis is no-checks C. The C compiler has no run-time power. Oh wait, wasn't specified if statement was C++ or the C++ subset of C. The code can do something shifty at run time, without a power surge, to the address reference before the address is de-referenced