It's not that is "incorrect", but using a bitwise OR that way he's forcing to every single expression to be evaluated, breaking the "short circuit" just to avoid some conditional branches. AND, if you take a look at optimized machine code geneted by the compiler, it makes
no difference:
Code:
; Assembly created by GCC, on Linux, for x86-64 mode, with '-O2 -mtune=native' options turned on.
; int f( char a )
; { return ( a == 'a' | a == 'e' | a == 'i' | a == 'o' | a == 'u' ); }
f:
lea ecx,[rdi-97]
xor eax,eax
cmp cl,20
ja .L1
mov eax,1065233
shr rax,cl
and eax,1
.L1:
ret
; int g( char a )
; { return ( a == 'a' || a == 'e' || a == 'i' || a == 'o' || a == 'u' ); }
g:
lea ecx,[rdi-97]
xor eax,eax
cmp cl,20
ja .L5
mov eax,1065233
shr rax,cl
and eax,1
.L5:
ret
; int h( char a )
; { return ( a >= '9' & a <= '9' ); }
h:
sub edi,'0'
xor eax,eax
cmp dil,9
setbe al
ret
; int i( char a )
; { return ( a >= '9' && a <= '9' ); }
i:
sub edi,'0'
xor eax,eax
cmp dil,9
setbe al
ret
I agree. This makes no sense.