TBF, that doesn't actually work - you have to write:
int fd; /* fd must be declared in order to be assigned */
if ((fd = open(...)) != -1) {
/* do something with fd */
} else {
perror("open");
}
which would be better written as:
int fd = open(...);
if (fd != -1) /* etc */
It would be nice for scoping reasons to be able to write something like:
if ((int fd = open(...)) != -1) /* etc */
but
if ((int fd == open(...)) != -1) /* etc */
isn't valid code.