Please save yourself from developing bad habits early in your programming careers. Never use goto. Also, conforming to modern coding conventions will allow you to be accepted amoung the OOP community. People won't laugh at you and your code.
Please save yourself from developing bad habits early in your programming careers. Never use goto. Also, conforming to modern coding conventions will allow you to be accepted amoung the OOP community. People won't laugh at you and your code.
- "Problem Solving C++, The Object of Programming" -Walter Savitch
- "Data Structures and Other Objects using C++" -Walter Savitch
- "Assembly Language for Intel-Based Computers" -Kip Irvine
- "Programming Windows, 5th edition" -Charles Petzold
- "Visual C++ MFC Programming by Example" -John E. Swanke
- "Network Programming Windows" -Jones/Ohlund
- "Sams Teach Yourself Game Programming in 24 Hours" -Michael Morrison
- "Mathmatics for 3D Game Programming & Computer Graphics" -Eric Lengyel
would using functions instead of goto slow down larger prorgams?
Generally, when you are attempting to make your program faster, you use a profiler or some other tool to identify what parts of your code need to be optimized. In most cases, you need only change your algorithm, and not the programming structures you are using to implement that algorithm.
It is possible, in some rare cases, that you might obtain a performance benefit from using goto over certain other options, however, you might as well use assembly if you really want the performance gain. If you are a C++ programmer, and you are worried about that type of overhead, then you should be using C. In most cases I would guess that the fear of the program being slower is unfounded and actually leads to more time being spent debugging and maintaining the goto than is saved by using it.
Wouldn't void functions that take no parameters be a close if not exact equivalent of a goto? It's a jump in code execution, with no added stack allocation/deallocation for parameters that I can think of.
Just Google It. √
(\ /)
( . .)
c(")(") This is bunny. Copy and paste bunny into your signature to help him gain world domination.
no. functions translate to CALL and RETURN type of assembly instructions. No parameter makes it so that less stuff needs to be PUSHed and POPed, but still is much slower. Aside from that, goto is one direction and doesn't return.Originally Posted by Hunter2
"You are stupid! You are stupid! Oh, and don't forget, you are STUPID!" - Dexter
yes, I think functions were a bad example. however lets use a "for instance". In the code example you presented you changed a while loop to a conditional goto. This gained nothing in the area of speed. The dissasembly should show pretty much the same output.Originally Posted by cgod
For the most part, code that uses a goto can directly translate to an easier to read construct. There are some occasions (when you haven't put any thought into your algorithm) that there is no direct translation and it would take a little more effort to convert the function. Best idea is to just not use it as a rule. It gains you nothing and causes a world of pain.
"You are stupid! You are stupid! Oh, and don't forget, you are STUPID!" - Dexter
I stand corrected.no. functions translate to CALL and RETURN type of assembly instructions. No parameter makes it so that less stuff needs to be PUSHed and POPed, but still is much slower.
I was thinking of a block of code that you goto, then at the end of the block there's another goto that jumps back to where you were. On second thought though, I realize that that still wouldn't work.Aside from that, goto is one direction and doesn't return.
Just Google It. √
(\ /)
( . .)
c(")(") This is bunny. Copy and paste bunny into your signature to help him gain world domination.