2 ms·
I'm writing a quick program that's supposed to compute something and print out the answer. I don't check the return value of printf(). Why not? 1. printf al
by AnimalMuppet 10y ago
I'm writing a quick program that's supposed to compute something and print out the answer. I don't check the return value of printf(). Why not?
1. printf almost never fails. If it does, I'm just going to re-run the program. If that doesn't work, I'll reboot and then re-run. On average, I waste less time with that approach than with checking the return value of printf.
2. If printf fails, what am I going to do? Print out an error message? But that might fail, too. Log something? That could also fail. Should I check the return values of those attempts, too?
But safety-critical code is usually not calling printf - it may not have a conventional output device at all. (It should have some mechanism for alerting the operator if there are failures, though.)