4 ms·
It 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 b
by wtetzner 6y ago
It 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.