9 ms·
Hm? The point is that compilers are allowed to assume that a pointer to x can never be formed by offseting a pointer to y (except if they are subobjects in the
by Sharlin 8y ago
Hm? The point is that compilers are allowed to assume that a pointer to x can never be formed by offseting a pointer to y (except if they are subobjects in the same array). But of course you’re not prevented from trying, either on purpose or accidentally, it just results in undefined behavior.
- chrisseaton 8y ago> it just results in undefined behavior. Right - I'm saying that if they need this macro then their program is not a defined C program in the first place. They should fix that, rather than trying to use a macro to work around the problem. The macro may break in the future if GCC adds other optimisations. They call it a 'miscompilation' - how can you 'miscompile' something which is undefined!
- Sharlin 8y agoBeing pragmatic and in the OS kernel business, they basically disagree with the standard here and say that tricks like that are necessary in kernel development (even if they might not be needed in the userland). Those parts of the kernel intrinsically cannot be portable anyway. From that perspective GCC is ”wrong” if it doesn’t at least provide an ”escape hatch” to disable optimizations in cases UB isn’t UB but in fact perfectly well-defined on that particular architecture.
- deleted 8y ago[deleted]
- toast0 8y agoInsisting that the environment matches the tooling seems backwards. The tooling needs to match the needs of the environment. That GCC may break your program in the future is one of the ways that people get locked into specific versions.
- chrisseaton 8y agoYou're making it sound like the C language has changed - it hasn't. I think this operation has been undefined in C as long as Linux has existed. They should not have written that code in the first place - it was never correct.
- wruza 8y agoThey maybe should not have written code in C at all, since the language that you need hire a lawyer for is not a viable option. But everyone hoped that with a given team they could create something that both will meet requirements and be future-proof. While what they did was not really legal, it is not practical to make it not work anymore. If they did it right way, Linux would not exist, see? Lawyers don’t build anything.
- Filligree 8y agoMaybe they shouldn't have, but there was no realistic alternative. At the time, C compilers weren't as "smart" and the sort of trickery they're doing was a perfectly reasonable thing to try in C. Today, if you were starting a kernel project from scratch, I'd think Rust would deserve a good, hard look.
- Sharlin 8y agoDo you really not grok the difference between writing platform-independent code and writing the platform itself? You don't write for an abstract machine as specified by the standard, you're writing for a very concrete real-world machine in order to implement a part of that abstract machine. Indeed, that's exactly what C was created for in the first place, for writing an OS in something else than assembly!
- deleted 8y ago[deleted]
- kjeetgill 8y agoAt some level you have to eventually decide, "if it works it works." Obviously at the application level it's frowned upon, but in the kernel? You do what you have to with the tools you have. Think about Java. Yea sure, keep telling us sun.misc.Unsafe isn't legit. It's going to get use until that capability exists elsewhere.
- taneq 8y ago> They call it a 'miscompilation' - how can you 'miscompile' something which is undefined! It simply implies that they consider themselves, rather than the C standard, as the authority on how C should behave.