Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Handling End Conditions

Name: Cudder !cXCudderUE 2017-01-27 17:54

C:
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.

Name: Anonymous 2017-01-28 1:14

>>1
doesn't that fuck with the call+ret prediction buffer?

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List