CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 2 of 2 FirstFirst 12
Results 16 to 30 of 30

Thread: Goto's?

  1. #16
    Join Date
    Apr 2005
    Location
    Norway
    Posts
    3,934

    Re: Goto's?

    Quote 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

  2. #17
    Join Date
    Oct 2006
    Location
    Sweden
    Posts
    3,654

    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.

  3. #18
    Join Date
    Feb 2005
    Location
    Normandy in France
    Posts
    4,590

    Re: Goto's?

    Quote 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()!

  4. #19
    Join Date
    Mar 2002
    Location
    St. Petersburg, Florida, USA
    Posts
    12,125

    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:

    "f(42)" = ????
    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

  5. #20
    Join Date
    Nov 2002
    Location
    California
    Posts
    4,556

    Re: Goto's?

    Quote 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

  6. #21
    Join Date
    Feb 2005
    Location
    "The Capital"
    Posts
    5,306

  7. #22
    Join Date
    Nov 2005
    Location
    Omaha, Nebraska, USA
    Posts
    696

    Re: Goto's?

    Quote 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.

  8. #23
    Join Date
    Mar 2001
    Posts
    2,529

    Re: Goto's?

    42:goto question
    ahoodin
    To keep the plot moving, that's why.

  9. #24
    Join Date
    Mar 2002
    Location
    St. Petersburg, Florida, USA
    Posts
    12,125

    Re: Goto's?

    Quote 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

  10. #25
    Join Date
    Nov 2005
    Location
    Omaha, Nebraska, USA
    Posts
    696

    Re: Goto's?

    Quote 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.

  11. #26
    Join Date
    Mar 2002
    Location
    St. Petersburg, Florida, USA
    Posts
    12,125

    Re: Goto's?

    Quote 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

  12. #27
    Join Date
    Nov 2005
    Location
    Omaha, Nebraska, USA
    Posts
    696

    Re: Goto's?

    Quote 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".

  13. #28
    Join Date
    Oct 2006
    Location
    Sweden
    Posts
    3,654

    Re: Goto's?

    I sense that this thread is going from "potential goto war" -> "it's friday"...

  14. #29
    Join Date
    Mar 2002
    Location
    St. Petersburg, Florida, USA
    Posts
    12,125

    Re: Goto's?

    Quote 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

  15. #30
    Join Date
    Apr 2005
    Location
    Norway
    Posts
    3,934

    Re: Goto's?

    Yep, it's Saturday 'morning' (strangely enough I can feel that in my bones, muscles, limbs and head...).

    Quote 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

Page 2 of 2 FirstFirst 12

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured