svn commit: r227812 - head/lib/libc/string

Dag-Erling Smørgrav des at des.no
Mon Nov 28 05:46:22 UTC 2011


David Chisnall <theraven at FreeBSD.org> writes:
> As to the | vs || issue - by all means change it to || if it fits
> better with the FreeBSD style.  In the general case I prefer to use |
> to hint to the compiler and readers of the code that short-circuit
> evaluation is not required and to remove a sequence point and make
> life easier for the optimiser.

The optimizer is smarter than you think, although it can sometimes get
confused when programmers start talking about what they want the
optimizer to do instead of what they want the program to do.

> In this case, the two are equivalent so it's just a hint to the
> reader, and apparently (judging by the responses so far) one that is
> not well understood.

The reader doesn't need a hint to understand what (n == 0 || s1 == s2)
means.  The reader will however need a couple of seconds to understand
what ((n == 0) | (s1 == s2)) means, and will waste a few more wondering
why the programmer didn't pick the more obvious solution.

DES
-- 
Dag-Erling Smørgrav - des at des.no


More information about the svn-src-head mailing list