Then why the hell was goto included with C???Originally posted by adrianxw
With C
Then why the hell was goto included with C???Originally posted by adrianxw
With C
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...
... 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.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
Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream.
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"
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.Originally posted by *ClownPimp*
As long as its used vary sparingly I dont see any downside to using 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.
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.
I was browsing the Half-Life Dedicated Server source code today and found this line...Code:fflush(stdin);
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!
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.
>>> 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.