best practice on precedence of variable declaration and error handling in C
- by guest
is there an advantage in one of the following two approaches over the other?
here it is first tested, whether fopen succeeds at all and then all the variable declarations take place, to ensure they are not carried out, since they mustn't have had to
void func(void) {
FILE *fd;
if ((fd = fopen("blafoo", "+r")) == NULL ) {
…