|
-
June 15th, 2007, 08:46 AM
#16
Re: Goto's?
 Originally Posted by MikeAThon
The other code constructs (like break and switch and continue) do not suffer from the "comes from" problem. You know exactly where the code is coming from, and its exact state when it arrives.
Well, actually when you got multiple continues/break within a loop you may lose track.
The major problem with 'goto' is IMO what TheCPUWizard mentioned. That you can easily jump over variable declaration/definition/initialization without ever being notified (not even a warning) and that may lead to strange results.
I see the "comes from" problem all the time, and to me it just another issue that I have to deal with when debugging.
Code:
int i = // some value
while (i > 0)
{
// do something...
}
// at this point i =< 0. How can I know if the above loop was ever entered?
// And if it was, how many iterations were there?
- petter
-
June 15th, 2007, 09:06 AM
#17
Re: Goto's?
I sure don't regret risking that war! This was interesting reading. 
I have to admit that I have never given much thought of how and why to get rid of break & continue in loops. Maybe I have seen them for so long that I'm just take their neccessity (and how is that spelled...) for being a law of nature but now I see your points.
-
June 15th, 2007, 09:49 AM
#18
Re: Goto's?
 Originally Posted by wildfrog
That you can easily jump over variable declaration/definition/initialization without ever being notified (not even a warning) and that may lead to strange results.
Your compiler is buggy:
Code:
#include <iostream>
int main() {
goto next;
int x=42; /* initializer or constructor */
next: std::cout << x;
}
Is ill-formed code.
A diagnostic message is required.
Most compilers generate a fatal diagnostic message (i.e. an error), which is a good thing.
"inherit to be reused by code that uses the base class, not to reuse base class code", Sutter and Alexandrescu, C++ Coding Standards.
Club of lovers of the C++ typecasts cute syntax: Only recorded member.
Out of memory happens! Handle it properly!
Say no to g_new()!
-
June 15th, 2007, 10:08 AM
#19
Re: Goto's?
Guess no one is going to tell me what the "Ultimate Question" was??
[reference to Hitchhikers Guide to the Galaxy....]
The "Ultimate Anwer" we know to be 42, so my code posted above, should give the question:
TheCPUWizard is a registered trademark, all rights reserved. (If this post was helpful, please RATE it!)
2008, 2009,2010
In theory, there is no difference between theory and practice; in practice there is.
* Join the fight, refuse to respond to posts that contain code outside of [code] ... [/code] tags. See here for instructions 
* How NOT to post a question here
* Of course you read this carefully before you posted
* Need homework help? Read this first
-
June 15th, 2007, 10:48 AM
#20
Re: Goto's?
 Originally Posted by TheCPUWizard
Guess no one is going to tell me what the "Ultimate Question" was??
[reference to Hitchhikers Guide to the Galaxy....]
The "Ultimate Anwer" we know to be 42, so my code posted above, should give the question:
D@mn!! If it wasn't for all those gotos, we would have been able to figure it out!!
Mike
-
June 15th, 2007, 01:18 PM
#21
Re: Goto's?
Can you help me with my homework assignment?, Before you post!, Use code tags, How to post!, Codeguru technical FAQs, C++ FAQ Lite, Stroustrup: C++ Style and Technique FAQ, Guru of the Week, Comeau C and C++ FAQs, Comeau C++ Templates FAQs, CUJ @ DDJ, Spam threshold
My Blogs : Learning C++ is fun | Abnegator's reflections
Open Threads : C++ Aha! Moments | Nature of work in C++?
-
June 15th, 2007, 02:21 PM
#22
Re: Goto's?
 Originally Posted by TheCPUWizard
Guess no one is going to tell me what the "Ultimate Question" was?? 
If it weren't for the division by 0 and the missing label, then maybe you'd be able to figure it out.
Of course, that's assuming there's nothing fundamentally wrong with the Universe.
-
June 15th, 2007, 02:41 PM
#23
Re: Goto's?
ahoodin
To keep the plot moving, that's why.

-
June 15th, 2007, 02:54 PM
#24
Re: Goto's?
 Originally Posted by ChaosTheEternal
If it weren't for the division by 0 and the missing label, then maybe you'd be able to figure it out.
Of course, that's assuming there's nothing fundamentally wrong with the Universe.
OK, i fixed the missing label (d)
But I dont see a divide by 0...
TheCPUWizard is a registered trademark, all rights reserved. (If this post was helpful, please RATE it!)
2008, 2009,2010
In theory, there is no difference between theory and practice; in practice there is.
* Join the fight, refuse to respond to posts that contain code outside of [code] ... [/code] tags. See here for instructions 
* How NOT to post a question here
* Of course you read this carefully before you posted
* Need homework help? Read this first
-
June 15th, 2007, 03:25 PM
#25
Re: Goto's?
 Originally Posted by TheCPUWizard
But I dont see a divide by 0... 
Code:
//...
goto b;
e:
if (x % 0)
goto b;
//...
Dev-C++, using the g++ compiler, gives a warning about it being a Divide by 0.
VS2005 gives the warning "potential mod by 0", but since it is Modulus division, it's still dividing by 0.
-
June 15th, 2007, 03:38 PM
#26
Re: Goto's?
 Originally Posted by ChaosTheEternal
Dev-C++, using the g++ compiler, gives a warning about it being a Divide by 0.
VS2005 gives the warning "potential mod by 0", but since it is Modulus division, it's still dividing by 0.
Told you "I didnt see it", did not say it didnt exist.
Yes "(x%0)" is mathematically undefined, I actually meant to use the much more useful "(x%1)"... (going back to edit again)....
TheCPUWizard is a registered trademark, all rights reserved. (If this post was helpful, please RATE it!)
2008, 2009,2010
In theory, there is no difference between theory and practice; in practice there is.
* Join the fight, refuse to respond to posts that contain code outside of [code] ... [/code] tags. See here for instructions 
* How NOT to post a question here
* Of course you read this carefully before you posted
* Need homework help? Read this first
-
June 15th, 2007, 03:47 PM
#27
Re: Goto's?
 Originally Posted by TheCPUWizard
Told you "I didnt see it", did not say it didnt exist.
I had to type something, and I hate just saying "Here".
-
June 15th, 2007, 03:56 PM
#28
Re: Goto's?
I sense that this thread is going from "potential goto war" -> "it's friday"...
-
June 15th, 2007, 11:27 PM
#29
Re: Goto's?
 Originally Posted by S_M_A
I sense that this thread is going from "potential goto war" -> "it's friday"... 
Nope..after midnight, now saturday!!!!
TheCPUWizard is a registered trademark, all rights reserved. (If this post was helpful, please RATE it!)
2008, 2009,2010
In theory, there is no difference between theory and practice; in practice there is.
* Join the fight, refuse to respond to posts that contain code outside of [code] ... [/code] tags. See here for instructions 
* How NOT to post a question here
* Of course you read this carefully before you posted
* Need homework help? Read this first
-
June 16th, 2007, 06:10 AM
#30
Re: Goto's?
Yep, it's Saturday 'morning' (strangely enough I can feel that in my bones, muscles, limbs and head...).
 Originally Posted by SuperKoko
Your compiler is buggy:
You're right. I'm using VC++ 2005.
I thought that TheCPUWizards code contained 'jumps over variable initializations', but when I look at the code now, I connot find it.. maybe it's been edited
- petter
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|