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-02-01 2:11

Here, not only does this work on multiple platforms but it handles any UTF-8 code points, making it globally aware, unlike your US imperialist glibc trash with its assumption that every "character" is 8 bits.

YES this program requires the end user to press ENTER when finished, seeking affirmative consent that they are ready to continue. A stark contrast to the rape culture of "getch".

*mic drop*

func main() {
reader := bufio.NewReader(os.Stdin)
r, _, e := reader.ReadRune()
if e == io.EOF {
...
}
...

r, _, e = reader.ReadRune()
if e == io.EOF {
...
}
...

r, _, e = reader.ReadRune()
if e == io.EOF {
...
}
...
}

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