3 ms·
If the standard didn't allow this optimization then GCC would have to emit unaligned access instructions everywhere. If it did that then people who want C to be
by nly 7y ago
If the standard didn't allow this optimization then GCC would have to emit unaligned access instructions everywhere. If it did that then people who want C to be 'close to the machine' would be complaining about lackluster performance and calling for everything to be written in ASM.
The reality is that the abstract machine modeled by C is a long, long way from what modern CPUs actually do, and the C language standards committee seems to have little interest in extending their language
- userbinator 7y agoIf you were compiling for an architecture that doesn't allow unaligned access, then you'd expect unaligned accesses to fault. If you were compiling for an architecture which does, then you'd wouldn't. That's what sane undefined behaviour should be expected to do.
- asveikau 7y ago> The reality is that the abstract machine modeled by C is a long, long way from what modern CPUs actually do, But some modern CPUs fault on unaligned access or make such access slower. (I think Intel is actually sometimes in the latter camp.) I don't get why people label "modern" as a synonym for their pre-existing favorite idea and then demand stuff reflect that "modernity" or else it is totally illegitimate. Seems like some kind of hangup. As some have mentioned in similar discussions, even the x86 machine code does not reflect how the CPU really works, there are things like caching and branch prediction and speculative execution and microcode and ... There is a long list and probably no one person is aware of all the abstractions.