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

goto is good

Name: Anonymous 2012-06-11 22:02

if you think otherwise you're a trendfag. goto is far more efficient than function calls for short blocks of code (lol compiler ignoring inline) and have a lot of neat applications.

Name: Anonymous 2012-06-12 2:01

goto can be used to implement a state machine rather than keeping a state variable and switching on it.


#include <stdlib.h>
#include <stdio.h>

int is_even(int n) {
    if (n < 0) n = -n;
even:
    if (n == 0) return 1;
    n--;
    goto odd;
odd:
    if (n == 0) return 0;
    n--;
    goto even;
}

int main(int argc, char **argv) {
    if (argc != 2 ) {
    fprintf(stdout, "Usage: %s <n>\n", argv[0]);
    exit(EXIT_FAILURE);
    } else {
    int n = atoi(argv[1]);
    puts(is_even(n) ? "true" : "false");
    }
    return 0;
}

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