Unix C - Portable WEXITSTATUS
OpenBSD's implementation of WEXITSTATUS
uses the address-of operator (unary &
) on its argument, effectively requiring that its argument have storage. You are calling it with the return value of a function, which doesn't have storage, so the compiler complains.
It is unclear whether OpenBSD's WEXITSTATUS
is POSIX-compliant, but the problem can be easily worked around by assigning the return value of pclose()
to a variable:
int status = pclose(proc);
printf("Exit code: %d\n", WEXITSTATUS(status));