Name: Cudder !cXCudderUE 2017-01-27 17:54
C:
C++:
Asm:
No need to check EOF everywhere. Less bloat than exceptions. Asm is superior.
c = getchar();
if(c == EOF)
...
...
c = getchar();
if(c == EOF)
...
...
c = getchar();
if(c == EOF)
...
...
C++:
int my_get_char() {
int c = getchar();
if(c == EOF)
throw EOF;
return c;
}
...
try {
...
c = my_get_char();
...
c = my_get_char();
...
} catch(int eof) {
...
}
Asm:
my_get_char:
cmp eax, EOF
jz is_eof
ret
is_eof:
pop eax
jmp eof_handler
...
call my_get_char
eof_at_1:
...
call my_get_char
eof_at_2:
...
call my_get_char
eof_at_3:
...
eof_handler:
cmp eax, eof_at_1
jz do_eof_at_1
...
No need to check EOF everywhere. Less bloat than exceptions. Asm is superior.