3 ms·
It's undefined even in single threaded code. The compiler can assume it's aligned and make optimizations which depend on it. It sounds like what you were doing
by cesarb 8y ago
It's undefined even in single threaded code. The compiler can assume it's aligned and make optimizations which depend on it.
It sounds like what you were doing is marking a struct as "packed", and accessing the fields directly (instead of through a pointer to the field). That should be fine.
- woadwarrior01 8y agoThis might be a bit too late to reply. It’s undefined in C, but it’s well defined at a processor level (on x86). IIRC, there was one particular bit of code that’d crash on AArch64 due to unaligned pointers, but would run a bit faster than aligned code on x86-64. On the other hand, this trick wouldn’t work in multithreaded code even if the semantics were well defined, due to false sharing of cache lines.