Actually, there could well be differences in the way the compiler generates the machine code.
A return will force a ret which is nice and quick, but a goto may well put in a jmp (to the ret) which is an extra op (and one that uses several clock cycles). After this function is called several thousand times the cycles add up. Even the use of 'if ... else ...' rather than 'if ... goto if ... goto' may be quicker as the former will probably cause a beq (or equivalent) to be used rather than a jeq (or equivalent). Of course, the compiler may well optimise the goto jmp to a ret, but you may not know that - and other compilers may not. There is also similar justification for only having a single return in a function. Any return will cause the stack to be unwound, and although it doesn't result in a loss of speed, it could result in larger code because the stack unwinding is done before every ret. There should be nothing religious about using gotos or not. It has its place (as others have said) - but you should use it with care. Laurence Mee -----Original Message----- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]]On Behalf Of Joe Programmer Sent: 28 November 2001 16:37 To: Palm Developer Forum Subject: Re: Compiler deadstripping valid source lines > >From: Aaron Ardiri > > goto's have valid reasons for usage, > > especially with exception handling.. --- Stringer wrote: > Please, please never ever ever ever use > 'goto' in a C or C++ programming. > Have a thousand returns, breaks and > continues before you ever have a single > goto. I don't want to start a religious war, but I have to side with Aaron on this. Sometimes using a goto makes the code much cleaner. However, it's very good to avoid goto when you are learning because it is so easily misused. For example, there is absolutely no difference between (a) if (something) return; and (b) if (something) goto end-of-function; Therefore, it's hard to support the statement that (b) can "never ever ever ever" be used. Edsger Dijkstra was just a neophyte programmer when he wrote the famous paper, "Go To Statement Considered Harmful," published in the "Communications of the ACM," Vol. 11, No. 3, March 1968. (See http://www.acm.org/classics/oct95/ if you're interested.) In fact, he's not really a programmer at all; he's a mathematician. (No offense to Paul.) __________________________________________________ Do You Yahoo!? Yahoo! GeoCities - quick and easy web site hosting, just $8.95/month. http://geocities.yahoo.com/ps/info1 -- For information on using the Palm Developer Forums, or to unsubscribe, please see http://www.palmos.com/dev/tech/support/forums/ -- For information on using the Palm Developer Forums, or to unsubscribe, please see http://www.palmos.com/dev/tech/support/forums/
