Thread: Someone used a goto...

  1. #16
    Registered User
    Join Date
    Sep 2002
    Posts
    1,640
    Originally posted by adrianxw
    With C
    Then why the hell was goto included with C???

  2. #17
    It's full of stars adrianxw's Avatar
    Join Date
    Aug 2001
    Posts
    4,829
    Presumably because the original authors of C were providing the same kind of functionality that was available in other programming languages of their era - it was a hell of a long time ago. Not all languages had structured if statements, for example. In Fortran-66 for example, an if is...

    IF(X.EQ.Y)statement

    ...where statement is a single statement, no compound statements allowed. As a result you often got blocks of code like...
    Code:
         IF(X.GT.1)GOTO 10
         Y=1
    10   IF[X.GT.2)GOTO 20
         Y=2
    20   IF(X.GE.3)GOTO 30
         Y=3
    30   CONTINUE
    ... if you are trying to encourage people to drop their language and use yours, you make it easy. When I coded in Fortran-66 I used GOTO, it was the only way to do certain things. I have not used a goto after the introduction of Fortran-77.
    Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream.

  3. #18
    Registered User
    Join Date
    Jan 2002
    Posts
    552
    Have you guys heard of yEnc, the new encoding method for binary attachments in Usenet? Well, I wrote some code that used that scheme and you'll never guess what I saw in the C implementation that i downloaded... it was nothing but goto's!! I mean, not a single for or while loop, all goto's! Needless to say, I quickly abandoned that implementation for a different one


    On another note, why has goto's become so evil in the eyes of so many? There are legitimate uses for them (IMHO), like jumping to code on an error, breaking from nested loops..., where the non-goto alternative would be less efficient and less readable.
    As long as its used [edit]very[/edit] sparingly I dont see any downside to using it

    *puts on fire-retarding suit in preparation for the [edit]inevitable[/edit]flames*

    [edit]for some reason I can't seem to spell today[/edit]
    Last edited by *ClownPimp*; 01-29-2003 at 05:10 PM.
    C Code. C Code Run. Run Code Run... Please!

    "Love is like a blackhole, you fall into it... then you get ripped apart"

  4. #19
    Me -=SoKrA=-'s Avatar
    Join Date
    Oct 2002
    Location
    Europe
    Posts
    448
    Originally posted by *ClownPimp*
    As long as its used vary sparingly I dont see any downside to using it
    That's the way I see goto's. Personaly I've never used one but imagine you're in the middle of a loop that's nested 5 or 6 times and you want to go to a place at the other side of the file. What do you do? Either use goto or a piece of code that only 4 people are able to understand 2 days after you wrote it.
    >>*puts on fire-retarding suit in preparation for the inevidable flames*
    Got a spare one?
    SoKrA-BTS "Judge not the program I made, but the one I've yet to code"
    I say what I say, I mean what I mean.
    IDE: emacs + make + gcc and proud of it.

  5. #20
    Unregd
    Guest
    This goto looks like subtratum from someone's previous programming experience in a programming language that shall remain nameless (cough, Q, cough, Basic, cough). For what my opinion's worth, if goto is necessary for the code as is, there is probably a more elegant solution without it. Someone be sure to remind that poor kid to write a program that displays, "I will not use goto in my C/C++ code," a hundred times.

  6. #21
    Banal internet user
    Join Date
    Aug 2002
    Posts
    1,380
    I was browsing the Half-Life Dedicated Server source code today and found this line...
    Code:
    fflush(stdin);

  7. #22
    Banned
    Join Date
    Jan 2003
    Posts
    1,708
    I don't see what's so bad with it. I mean you are after all using a language where false is synonomous with excitement (!).

    Jane: Oh Robert! Oh Robert!
    Robert: What? My sex is evaluating to false? I'm a bad lover!

  8. #23
    Registered User dirkduck's Avatar
    Join Date
    Aug 2001
    Posts
    428
    Oh come on now, its not that bad. I mean if its not overused, it can be handy get get out of/into a loop or whatnot without a load of if's.

  9. #24
    It's full of stars adrianxw's Avatar
    Join Date
    Aug 2001
    Posts
    4,829
    >>> it can be handy get get out of/into a loop or whatnot

    That is the usual justification. I would say that it is not valid, you can always get out of nested structures, and I would also say that if your program has very deeply nested structures, there was probably a better way of doing it anyway.
    Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. temperature sensors
    By danko in forum C Programming
    Replies: 22
    Last Post: 07-10-2007, 07:26 PM
  2. goto command
    By jhwebster1 in forum C Programming
    Replies: 3
    Last Post: 02-21-2006, 12:32 PM
  3. Does goto have a glitch or...?
    By Blackroot in forum C++ Programming
    Replies: 9
    Last Post: 02-18-2006, 10:40 AM
  4. helpppp
    By The Brain in forum C Programming
    Replies: 1
    Last Post: 07-27-2005, 07:05 PM
  5. Need some help with a basic tic tac toe game
    By darkshadow in forum C Programming
    Replies: 1
    Last Post: 05-12-2002, 04:21 PM