# [PATCH] use || instead of | in logical expressions

2 messages from 2009-01-01 to 2009-01-01. Participants: Alexander Potashev.
Thread: https://gitlist.dev/t/16955

## Alexander Potashev, 2009-01-01 22:39

Subject: [PATCH] use || instead of | in logical expressions
Message-ID: <20090101223953.GA16680@myhost>
URL: https://gitlist.dev/e/20090101223953.GA16680%40myhost

```
Bit OR ('|') is probably faster and it always works correctly (but '&'
doesn't!), but it looks horrible here.

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

```

## Alexander Potashev, 2009-01-01 23:07

Subject: Re: [PATCH] use || instead of | in logical expressions
Message-ID: <20090101230746.GA17008@myhost>
URL: https://gitlist.dev/e/20090101230746.GA17008%40myhost
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.

> 
> 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
> 

```
