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-29 8:36

>>14
yes, but you have to write machine-specific code for each system, which is something you avoid as much as possible when going for portability. sometimes you can't avoid it and sometimes you shouldn't (careful asm is probably the best way to ensure constant-time performance in crypto) but in general, portable is better than machine-specific

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