2 ms·
one should never get in the way of a good rant. more seriously, what I'd like to see in C (as a long-time programmer in C) is less freedom around undefined beh
by Upvoter33 6y ago
one should never get in the way of a good rant.
more seriously, what I'd like to see in C (as a long-time programmer in C) is less freedom around undefined behavior. I used to feel like the biggest mistakes made in C were around pointer bugs, but you can be careful and get things like that (mostly) right. Undefined code is a lot harder to see and avoid without a very deep understanding of lots of small details.
- wtetzner 6y agoIt would be very nice if there was a special C compiler that could just warn about all occurrences of undefined behavior in a program. It doesn't even need to be able to generate code, it could just be a front-end that points out the places where undefined behavior is either being invoked, or could be invoked depending on the input to the program.
- MauranKilom 6y agoDoes this piece of code have UB? Could it invoke UB depending on the input to the program? void count(int x) { for (int i = 0; i < x; ++i) printf("%d ", i); } The answer to the latter question is of course "yes" - signed integer overflow is UB, so you invoke UB by passing a negative x. Would you like every loop to be flagged as potential UB? I don't think you'd last a single day programming in that C dialect.
- wtetzner 6y agoYou wouldn't use the compiler to build you programs, you'd just use it to detect UB. It would be especially useful if you could specify your entry point(s), and let it find all cases where user inputs could cause UB. I think it would be especially helpful for checking the output of compile-to-c languages.
- wool_gather 6y agoI assume you've seen John Regehr's "Proposal for a Friendly Dialect of C"? https://blog.regehr.org/archives/1180 https://blog.regehr.org/archives/1180 The basic idea is to replace various common UB scenarios with "defined, but unspecified", in order to move the compiler's interpretation of the program closer to the programmer's.