slightly OT: c expression evaluation order

Marcus Meissner marcus at jet.franken.de
Sat Jul 24 13:54:13 CDT 2004


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



More information about the wine-devel mailing list