(this question is an exact copy of Is compound if checking for null and then other condition in C++ always safe? but about C, not C++. It was pointed out that the question should be more specific).
I have been using the following type of if
condition for a lot of time.
char* ptr = ...;
if (ptr != NULL && ptr[0] != '\0') // <=== is this always safe?
{ /* ... */ }
It relies on ptr != NULL
being checked before ptr[0] !='\0'
.
Is it safe under all standards, compilers, architectures? Or is there a possibility that ptr[0] != '\0'
will be checked before ptr != NULL
?