Hello,
this is slightly of topic for this mailing list. However, it would be nice if someone could answer my question. I've seen that Alexandre changed the if statement expression in one of my patches from
if (pszProvider ? *pszProvider == '\0' : 1)
to
if (!pszProvider || !*pszProvider)
I've always thought that the order in which subexpressions are evaluated is not specified in the C language. Isn't there the danger of a NULL pointer dereference given here?
Thanks, Michael
On Sat, Jul 24, 2004 at 08:38:25PM +0200, Michael Jung wrote:
Hello,
this is slightly of topic for this mailing list. However, it would be nice if someone could answer my question. I've seen that Alexandre changed the if statement expression in one of my patches from
if (pszProvider ? *pszProvider == '\0' : 1)
to
if (!pszProvider || !*pszProvider)
I've always thought that the order in which subexpressions are evaluated is not specified in the C language. Isn't there the danger of a NULL pointer dereference given here?
boolean short circuit evaluation always goes from left to right.
So !pszProvider is checked first, and the whole expression evaluation stopped at that point.
The construct Alexandre used is very common.
Ciao, Marcus