Considering fopen() fails, in the following piece of code:
FILE *fp = fopen("file.txt", "w");
if (fp == NULL) {
printf("Error occurred while opening file, errno=%d, %s\n",
errno, strerror(errno));
exit(1);
}
Since the order in which function arguments are evaluated is unspecified in C, while invoking printf(), in case call to strerror() is evaluated (invoked) first and it fails, wouldn't errno be set to something else when the line actually gets printed? Or, is it that errno would have been copied into the activation record of printf() even before evaluating strerror() and hence would remain unchanged? Is this unspecified behaviour?
EDIT:
Yes, I do understand that I can save errno to some int right after fopen(), but that's not my point here. I am trying to figure out how the above piece of code behaves.