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

Pages: 1-4041-

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: Cudder !cXCudderUE 2017-01-27 17:55

Of course my_get_char should start with a call getchar.

Name: Anonymous 2017-01-27 18:35

>>2
So basically if your language has tail calls it's as good as ASM. C and C++ don't so they suck.

Name: Anonymous 2017-01-27 20:53

Name: Anonymous 2017-01-27 22:43

>>4
wew

Name: Anonymous 2017-01-27 23:19

>>3
C/C++ has TCO.

Name: Anonymous 2017-01-28 0:18

Name: Anonymous 2017-01-28 1:14

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

Name: Anonymous 2017-01-28 1:20

>>8
tfw computers have optimized for dumb languages and compilers

Name: Anonymous 2017-01-28 4:44

You can do exactly the same thing in C with goto and jmp_buf.

For how long do you plan to keep making these posts about micro-optimizing your assembly code? This is stuff that 14-year-olds find interesting after they've discovered ASM for the first time and subsequently grow out of when they realize it has no bearing on writing real software. You're basically still masturbating with bit-twiddle kiddy shit while the grown-ups have moved on to fucking their ENTERPRISE-grade vaginas.

Name: Cudder !cXCudderUE 2017-01-28 5:54

>>10
Yes, setjmp/longjmp works but it's still more bloated than literally 2 instructions.

they realize it has no bearing on writing real software
If "real software" means bloated, slow, unreliable masses of complexity that barely work, I don't care about that. Open your mind and see what computers can really do.

Name: Anonymous 2017-01-28 7:57

yeah, software is unreliable because people don't microoptimize every single fucking thing to the level of a single CPU cycle. meanwhile, your solution has one flaw that is pretty serious from the perspective of a software project that is supposed to be used by more than one person or maybe on a one specific system: it's restricted to x86.

Name: Anonymous 2017-01-28 16:53

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

>>12
You can do the same on any other system.

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

Name: Anonymous 2017-01-29 9:27

Name: Cudder !cXCudderUE 2017-01-29 18:02

>>15
Bullshit.

Name: Anonymous 2017-01-30 2:17

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 {
...
}
...
}

Name: Anonymous 2017-02-01 3:57

>>19
What programming language is this?

Name: Cudder !cXCudderUE 2017-02-01 4:07

>>19
if e == io.EOF
if e == io.EOF
if e == io.EOF
if e == io.EOF
if e == io.EOF
if e == io.EOF
if e == io.EOF
if e == io.EOF
if e == io.EOF

Congratulations, you completely missed the fucking point.

Name: Anonymous 2017-02-01 4:46

>>21
#define MAKE_CUDDER_SHUT_UP if e == io.EOF

Name: Anonymous 2017-02-01 5:01

>>9
Whom are you quoting?

Name: Anonymous 2017-02-01 5:44

c = getchar();
while(!(c == EOF)){
dosomethingwiththecharhere(c);
c= getchar();
}

Name: Anonymous 2017-02-01 6:03

lazy simd style
eofloc = sum((c.==EOF).*[0:length(c)];

Name: Anonymous 2017-02-01 7:59

>>22
nice dubs

Name: Anonymous 2017-02-01 12:26

>>24
Terrible, at least use a do-while loop so you don't need to have two c = getchar() statements.

Name: Anonymous 2017-02-01 13:40

>>24
Isn't the following the same?
for(; (c = getchar()) != EOF; )
dosomethingwiththecharhere(c);

Name: Anonymous 2017-02-01 17:15

Name: Anonymous 2017-02-02 0:27

>>21
Typical white male programmer response.

Name: Anonymous 2017-02-02 1:38

>>27
Terrible, at least use a goto so you don't need to have two c = getchar() statements.

Name: Anonymous 2017-02-02 2:56

>>28
Slightly more for-loop like, also with a blank first iter
for(c = ''; c != EOF; c = getchar())
dosomethingwiththecharhere(c);

Name: Anonymous 2017-02-02 3:03

Name: Anonymous 2017-02-02 3:28

­

Name: Anonymous 2017-02-02 3:29

­

Name: Anonymous 2017-02-02 3:29

­­

Name: Anonymous 2017-02-02 3:29

­

Name: Anonymous 2017-02-02 3:29

­

Name: Anonymous 2017-02-02 3:29

­

Name: Anonymous 2017-02-02 3:30

­

Name: Anonymous 2017-02-02 3:30

­

Name: Anonymous 2017-02-02 3:30

­

Name: Anonymous 2017-02-02 3:30

­

Name: Anonymous 2017-02-02 3:30

claiming my dubz

Name: Anonymous 2017-02-02 4:17

Name: Anonymous 2017-02-02 5:09

>>34-44
Fuck all the way off

Name: Anonymous 2017-02-02 6:22

Name: Anonymous 2017-02-02 7:43

>>46
Xarn?

Name: Anonymous 2017-02-02 16:29

Name: Anonymous 2017-02-03 1:30

Fuck part of the way on

Name: Anonymous 2017-02-03 1:54


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