Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Your friendly wg14 member here. It is a low-level language, but it is not a portable assembler. If you think you what you will write will have a one-to-one relationship to assembler you will run in to trouble. If you want a deeper dive in to how these things can trip you up, watch: https://youtu.be/w3_e9vZj7D8


C programmer and fan of yours.

I agree with you, but if you could convince WG14 to remove a lot of the stupid UB, that would be closer to the case.

(I know you're trying from your "One Word Broke C" article. Which, by the way, is putting up a server error right now.)


> it is not a portable assembler

And it never was!

Just keeping this point in mind would reduce the plethora of discussions about undefined behaviour to the essential, i.e. the useful discussions, i.e. the 0.1%.


Opinion is divided on this. My best guess is that ISO C was never a portable assembler, but the C programming language before standardisation broadly was, and that's how people hold both positions as self evidently true. Different definition of "C".


Programmers are supposed to trust official interfaces rather than undocumented implementation details ;-P


C would have been great as a portable assembler. E.g. if a syntactic + mapped to the hardware `add` instruction, that's pretty predictable! But it doesn't; it maps to the hardware `add` modulo compiler optimizations (like folding and strength reduction, which are done assuming overflow and other tricky parts are UB). Basically everywhere UB is permitted by the spec is so compilers don't have to handle the tricky cases, don't have to give semantics for buggy programs, or even help in debugging, and can make what would be unsound optimizations if the operations truly represented the target CPU's "weird" add semantics.


Just toss enough compiler flags at clang and make sure to occasionally use inline asm snippets to throw off the compiler's optimizations.

Then you're GTG


Depends on what you mean by "portable assembler". It is exactly that in a lot of ways, but exactly not that in others.

I think it's more useful to say that C is a portable assembler, than it is to say that it isn't, considering how it's used in practice and the sort of nasty things C compilers do in order to make that possible.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: