Begginer Question

This is a discussion on Begginer Question within the C++ Programming forums, part of the General Programming Boards category; hi, I started c++ not long ago and I did 2 files in 1 project. now I know main(); will ...

  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
    21,451
    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
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    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,475
    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 ).
    I'm just trying to be a better person - My Name Is Earl

  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, 12:47 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21