git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH] use || instead of | in logical expressions

From
APAlexander Potashev <aspotashev@gmail.com>
Date
Jan 1, 2009, 23:07 UTC
Message-ID
<20090101230746.GA17008@myhost>
In-Reply-To
<20090101223953.GA16680@myhost>
On 01:39 Fri 02 Jan     , Alexander Potashev wrote:
> Bit OR ('|') is probably faster and it always works correctly (but '&'
> doesn't!), but it looks horrible here.

Sorry, I was wrong: '&' would work as well (for example in expression '(a < 1) & (b == 5)') because logical operators can return only 0 or 1.

Show 22 quoted lines
> 
> Signed-off-by: Alexander Potashev <aspotashev@gmail.com>
> ---
>  builtin-apply.c |    2 +-
>  1 files changed, 1 insertions(+), 1 deletions(-)
> 
> diff --git a/builtin-apply.c b/builtin-apply.c
> index 07244b0..c71afa1 100644
> --- a/builtin-apply.c
> +++ b/builtin-apply.c
> @@ -2487,7 +2487,7 @@ static int check_patch(struct patch *patch)
>  		ok_if_exists = 0;
>  
>  	if (new_name &&
> -	    ((0 < patch->is_new) | (0 < patch->is_rename) | patch->is_copy)) {
> +	    (0 < patch->is_new || 0 < patch->is_rename || patch->is_copy)) {
>  		if (check_index &&
>  		    cache_name_pos(new_name, strlen(new_name)) >= 0 &&
>  		    !ok_if_exists)
> -- 
> 1.6.0.6
> 
Previous: Alexander Potashev
Message 2 of 2 in “use || instead of | in logical expressions”
  1. use || instead of | in logical expressionsAlexander Potashev, Jan 1, 2009
  2. Alexander PotashevJan 1, 2009

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.