Thread: Begginer Question

  1. #1
    Registered User
    Join Date
    Apr 2008
    Posts
    11

    Begginer Question

    hi, I started c++ not long ago and I did 2 files in 1 project.
    now I know main(); will always be execute first but how do I execute only the submain();?(my other function of the file)?

    pls help?

    P.S.: how do I use the goto command?

  2. #2
    Beginner in C++
    Join Date
    Dec 2007
    Posts
    34
    I don't think it's possible to run a program without Main being called, could be wrong.
    Ubuntu Linux / Vista Home Premium (for games)
    SCiTE text editor, G++ compiler

  3. #3
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    now I know main(); will always be execute first but how do I execute only the submain();?(my other function of the file)?
    You call it from main().

    P.S.: how do I use the goto command?
    With great skill, or not at all
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  4. #4
    Its hard... But im here swgh's Avatar
    Join Date
    Apr 2005
    Location
    England
    Posts
    1,688
    Hehe great answer laserlight

    Goto is in C++ and is a "label" selection structure. But, in all honesty, like laserlight said, it should be avoided in all cases excpet in extreme circumstances, ( getting out of a deeply nested for loop structure could be one ).
    Double Helix STL

  5. #5
    Registered User
    Join Date
    Apr 2008
    Posts
    890
    Quote Originally Posted by swgh View Post
    Hehe great answer laserlight

    Goto is in C++ and is a "label" selection structure. But, in all honesty, like laserlight said, it should be avoided in all cases excpet in extreme circumstances, ( getting out of a deeply nested for loop structure could be one ).

    And at that point, goto only further compounds the bad code, which should be refactored.

  6. #6
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by medievalelks View Post
    And at that point, goto only further compounds the bad code, which should be refactored.
    Most likely yes. Although I have (here at work) a funciton where I counted 13 goto's [although all go to the same label, at least] - yes, it's driver code, and it will not be refactored any time soon.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Alice....
    By Lurker in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 06-20-2005, 02:51 PM
  2. Debugging question
    By o_0 in forum C Programming
    Replies: 9
    Last Post: 10-10-2004, 05:51 PM
  3. Question about pointers #2
    By maxhavoc in forum C++ Programming
    Replies: 28
    Last Post: 06-21-2004, 12:52 PM
  4. Question...
    By TechWins in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 07-28-2003, 09:47 PM
  5. Question, question!
    By oskilian in forum A Brief History of Cprogramming.com
    Replies: 5
    Last Post: 12-24-2001, 01:47 AM