News for hackers. Stuff that matters.
Re:Bugs in Hello World by paavoova on Wednesday March 09, 2022 @02:25PM (#30618884)
Your usage of errno can cause failure on success if errno was set any time before the call to fflush. Might need a bump to v3 for robustness...
Re:Bugs in Hello World by gpm on Wednesday March 09, 2022 @03:00PM (#30619261)
According to cppreference

> The value of errno is 0 at program startup, and although library functions are allowed to write positive integers to errno whether or not an error occurred, library functions never store 0 in errno.

https://en.cppreference.com/w/c/error/errno

So this program correctly tests whether printf or fflush wrote to errno. You just can't refactor it into a function you call not at startup... I suppose that is unless you're keeping to a convention where you always set errno back to 0 after any call that might have set it...