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

[ Available lists | Index of svn-src-head | Month of Nov 2011 | Week of 28 Nov 2011 | Raw email | View thread | Wrap long lines | Reply ]
From
Dag-Erling Smørgrav <des@des.no>
Date
28 Nov 2011 05:46:22
Subject
Re: svn commit: r227812 - head/lib/libc/string
Message-ID
86vcq4er4l.fsf@ds4.des.no


[ Hide this part ]
David Chisnall <theraven@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 Smrgrav - des@des.no

Elapsed time: 0.157 seconds