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

goto

Name: Anonymous 2011-12-15 15:55

why should i write:

while(faggot){
  ...
}

when it just gets turned into:

w1:
   if(faggot) goto w1e;
   ...
   goto w1;
w1e:
   ...

Name: Anonymous 2011-12-15 16:28

>>1
Because they're not the same. Loops can be split up, unrolled, or merged by the compiler as long as they perform as required by the C standard. They could use a fast compare-and-branch or increment/decrement-and-branch instructions, if possible, instead of setting flags or a condition register. if...goto hinders optimization and compile-time analysis and will make your code run slower in most, if not all, compilers. You also need to make sure there are no name conflicts in labels. That can easily become a jumbled mess of spaghetti code. If you have nested loops or move loops around, your system of w1:, w1e:, etc. labels could become unorganized. If you change the names, you might forget a label and have bugs without knowing why. C gives you looping constructs, so use them.

Name: Anonymous 2011-12-15 16:55

Note to all the faggots that use goto: it is a terrible programming practice, and the more you use it, the more you will fuck yourself.

Name: Anonymous 2011-12-15 17:00

>>12
Note to all faggots that use iteration: it is a terrible programming practice, and the more you use it, the more you will fuck yourself.

Name: Anonymous 2011-12-15 17:11

>>11-san, good job

  ∧_∧   ∧_∧   ∧_∧   ∧_∧      ∧_∧
 ( ・∀・)   ( `ー´)  ( ´∀`)  ( ゚ ∀゚ )    ( ^∀^)
 (    つ┳∪━━∪━∪━━∪━∪━∪━┳⊂     つ
 | | |  ┃This thread has peacefully ended.┃ | | |
 (__)_) ┻━━━━━━━━━━━━━━┻ (__)_)     Thank you.

Name: Anonymous 2011-12-15 17:45


  ∧_∧   ∧_∧   ∧_∧   ∧_∧      ∧_∧
 ( ・∀・)   ( `ー´)  ( ´∀`)  ( ゚ ∀゚ )    ( ^∀^)
 (    つ┳∪━━∪━∪━━∪━∪━∪━┳⊂     つ
 | | |  ┃This thread has VIOLENTLY RISEN.┃ | | |
 (__)_) ┻━━━━━━━━━━━━━━┻ (__)_)     FUCK you.

Name: Anonymous 2011-12-15 17:55

I'd like to take a moment to point out that >>1-san's code is wrong.  In fact, his two snippets are the exact opposite of each other.

Name: Anonymous 2011-12-15 17:59

>>16
everyone already noticed that, but no one other than you gave enough fucks to point it out.

Name: Anonymous 2011-12-15 18:09

isn't evolution great? It creates things out of nothing, and makes them automatically better! and on top of that, you dont hafta worry about it at all! it just works! AND IT'S NATURAL

Name: Anonymous 2011-12-15 18:25

>>17
ENOFUCKS

Name: Anonymous 2011-12-15 19:39

I only use gotos when I would otherwise use lots of flags. Like:


void fn(int* data, int iterations) {
  for(int iteration = 0; iteration < iterations; ++iteration) {
    for(x=0; x<W; ++x) {
      for(y=0; y<L; ++y) {
        if(iterationISdone(x,y,data)) goto done;
        ...
      }
    }
  done:
  }
}


Without gotos, this would likely be expressed as:


void fn(int* data, int iterations) {
  for(int iteration = 0; iteration < iterations; ++iteration) {
    int keepGOING = 1;
    for(x=0; keepGOING && x<W; ++x) {
      for(y=0; keepGOING && y<L; ++y) {
        if(iterationISdone(x,y,data)) {
          keepGOING = 0;
          break;
        }
        ...
      }
    }
  }
}


Although you could avoid gotos and flags by using a helper function, and returning from the helper function at an arbitrary point:


void performITERATION(int* data) {
  for(x=0; x<W; ++x) {
    for(y=0; y<L; ++y) {
      if(iterationISdone(x,y,data)) return;
      ...
    }
  }
}

void fn(int* data, int iterations) {
  for(int iteration = 0; iteration < iterations; ++iteration)
    performITERATION(data);
}

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