Hacker News new | comments | show | ask | jobs | submit login

Conditionals are evaluated left to right chris. It's no different than any other conditional. An assignment simply evaluates to the lvalue.

According to C99, 6.5.16 clause 4, the order of evaluations on operands is undefined and if an attempt is made to modify or access the operand is after the next sequence point then the behavior is undefined.

Chris, && and || are short-circuited operators that create sequence points. They are exceptions to that rule.

except where noted [e.g. special rules for && and ||], the order of evaluation of operands of individual operators and subexpressions of individual expressions, and the order in which side effects take place, is Unspecified.

This is basic stuff Chris, let's not debate the obvious, this kind of code is all over the place in the Linux kernel.

I appreciate your candour. Can you point me to where this sort of thing is used in the Linux kernel? It looks like it is frowned on to me:

* http://linux-kernel.2935.n7.nabble.com/PATCH-drivers-net-ifb...

* http://linux-kernel.2935.n7.nabble.com/PATCH-1-4-silicom-che...

* http://linux-kernel.2935.n7.nabble.com/PATCH-0-4-Staging-sil...

Not to mention, checkpatch.pl checks for assignments in if statements:


I should point out that someone tried to add a backdoor into the Linux kernel source through the use of an assignment in an if statement in 2004. What are your thoughts on this?


Also, where is the place in the C99 standard that details the exception? Genuinely curious. When I reviewed the standard, all that is said about the if statement is in section, and that says nothing about short circuited logic, certainly nothing about "exceptions to the rule". This seems compiler specific, but I'm happy to be shown to be wrong - if you can point me to the part in the standard.

Guidelines | FAQ | Support | API | Security | Lists | Bookmarklet | DMCA | Apply to YC | Contact