3 ms·
> I need to have uint8_t* pointers into the middle of buffers which I can then typecast into byte-aligned structs. Quite a lot of CPUs would just trap here. A
by sklogic 11y ago
> I need to have uint8_t* pointers into the middle of buffers which I can then typecast into byte-aligned structs.
Quite a lot of CPUs would just trap here. Assuming that unaligned access is allowed is a sin.
- Nursie 11y agoReally? Because this is very common practice in device or network code, in my experience.
- sklogic 11y agoYes, it is a very common crap indeed. I had a lot of pain porting some Linux filesystems to Sparc, for example (had to give up back then, that code was beyond any hope). Not to mention the endianess issues, an often sight in the crappy networking code.
- bluetomcat 11y ago> Quite a lot of CPUs would just trap here Or even worse -- for example, ARM CPUs usually round-down the misaligned address to the closest boundary when alignment checking is disabled. This means that attempting to access a 4-byte int at location 11 will silently let the CPU access it at location 8. This can manifest in some very nasty bugs.
- stephencanon 11y agoIIRC this behavior went away in ARMv6.