4 ms·
It targets the abstract machine, but the dispute here is about what should happen when the program operation goes into territory that the abstract machine does
by vyodaiken 8y ago
It targets the abstract machine, but the dispute here is about what should happen when the program operation goes into territory that the abstract machine does not specify. And C code is EXPECTED to go beyond the territory of the abstract machine.
- geofft 8y ago> And C code is EXPECTED to go beyond the territory of the abstract machine. Passive voice! You expect C code to go beyond the territory of the abstract machine. The authors of the standard, quite clearly, do not. I can see both of these arguments. I think there is a place in the world for a C that is machine-specific. But it's clearly not what the standard authors have in mind, there are clearly people who find the genericness of C useful (cf. "portable assembler"), and piecemeal solutions like skipping individual bad optimizations won't solve the underlying problem that there's no way in C to say "Dude, I'm writing for a reasonable UNIX on a reasonable modern machine with a single flat address space for code and data and non-exception-raising two's-complement arithmetic and the ability to do nonaligned reads/writes and other normal things, please stop thinking I might also be writing for a PDP-11 bootloader." I think you should go to the standards committee with a single proposal, which is that C should stop trying to be portable to weird / old architectures (and people who need them can use weird / old compilers, anyway). Among other things, you can now enable certain types of optimizations if the compiler is permitted to assume that arithmetic is two's-complement and nonaligned reads/writes work and so forth.
- cesarb 8y ago> if the compiler is permitted to assume that [...] nonaligned reads/writes work One of the most popular architectures for "a reasonable UNIX on a reasonable modern machine with a single flat address space for code and data" is the x86, and on it, some nonaligned reads/writes do trap. Certain optimizations can be done only if the compiler is permitted to assume that the data is aligned.
- vyodaiken 8y agoAs usual, this is pure handwaving: " certain optimizations ... "
- vyodaiken 8y ago>You expect C code to go beyond the territory of the abstract machine. The authors of the standard, quite clearly, do not. That is 100% wrong. >Strictly conforming programs are intended to be maximally portable among conforming implementations. Conforming programs may depend upon nonportable features of a conforming implementation. The whole concept of "undefined behavior" is to cope with the reality that C programs routinely go beyond the bounds of the abstract machine.