Originally Posted by
Hodor
Stop showing code that is plainly incorrect, please. First, your use of bitwise OR (|) is dumb and incorrect. Second, even if it was correct it'd be obfuscated and that's not good. The correct expression should be using boolean OR (||).
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
Originally Posted by
Hodor
... "utilise the MUL instruction to set and address to goto when a statement is false to and then use the GOTO instruction". ... and makes no sense at all...
I agree. This makes no sense.