Thread: declair fucntions before main()?

  1. #16
    Ahhhh, I see now. That clears that up.

  2. #17
    Refugee face_master's Avatar
    Join Date
    Aug 2001
    Posts
    2,052
    Code:
    #include <iostream.h>
    
    void function();
    	
    int main()
    {
    	cout << "In main\n";
    	function();
    	cout << "Back in main\n";
    
    	return 0;
    }
    
    void function()
    {
    	cout << "In function\n";
    }

  3. #18
    Registered User
    Join Date
    Jan 2003
    Posts
    311
    Having prototypes, then main, then the functions proper ends up with main somewhere in the middle of your code. I find this annoying. If you avoid prototypes whenever possible you also get a kind of cheap information hiding, as no function can ever call a function that occurs after it.

    The only reason that I can see to do it any other way is because that's the way you were taught. I strongly suspect that if you asked the person who taught you to do it that way, they would say that "it's the way they were taught" If you kept the chain going I will bet money you would eventually reach a person who says "because it's done that way in COBOL"

  4. #19
    Registered User
    Join Date
    Jan 2002
    Posts
    75
    I am definately a supporter of function prototypes before main...for the major reason that Im able to see all of the different functions mostly all at once...because often I forget what functions I have already created...and i can often miss what I already have when I have to dig through all sorts of function definitions...
    MSVC++~

  5. #20
    Senior Member joshdick's Avatar
    Join Date
    Nov 2002
    Location
    Phildelphia, PA
    Posts
    1,146
    Originally posted by Supar
    I am definately a supporter of function prototypes before main...for the major reason that Im able to see all of the different functions mostly all at once...because often I forget what functions I have already created...and i can often miss what I already have when I have to dig through all sorts of function definitions...
    I agree. It's very helpful to see all of my function declarations at once. Then, I can see what type the functions are returning and what parameters they are accepting. This is useful when I need to see what all of functions are doing in case I need to change them.

    grib, function prototypes aren't just needless code. They greatly increase code readability. Also, I disagree that function prototypes leave main in the middle of one's program. Before main, one should already have comments, includes, and constant definitions. Function prototypes would only take up at most I'd say ten lines. If you any more functions than that, you should seriously consider if there is an easier way to organize your program such as making a class.
    FAQ

    "The computer programmer is a creator of universes for which he alone is responsible. Universes of virtually unlimited complexity can be created in the form of computer programs." -- Joseph Weizenbaum.

    "If you cannot grok the overall structure of a program while taking a shower, you are not ready to code it." -- Richard Pattis.

  6. #21
    If you any more functions than that, you should seriously consider if there is an easier way to organize your program such as making a class.
    It could be a large application like a game or something. but if it is you should divide some of it up into header files.

  7. #22
    Senior Member joshdick's Avatar
    Join Date
    Nov 2002
    Location
    Phildelphia, PA
    Posts
    1,146
    That's exactly what I was suggesting. If you really have that many functions, you ought to think about putting them somewhere else like in a header file or a class.
    FAQ

    "The computer programmer is a creator of universes for which he alone is responsible. Universes of virtually unlimited complexity can be created in the form of computer programs." -- Joseph Weizenbaum.

    "If you cannot grok the overall structure of a program while taking a shower, you are not ready to code it." -- Richard Pattis.

  8. #23
    Registered User
    Join Date
    Jan 2003
    Posts
    311
    I don't have anything against protypes per se. far from it. It's the functions comming after main() that I find mildly annoying. On a large project the file containing main is usually fairly sparse anyway. Still I like to be able to jump to the end of the file and then start reading upwords. I look at it like top-posting.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. pointers
    By InvariantLoop in forum C Programming
    Replies: 13
    Last Post: 02-04-2005, 09:32 AM
  2. confused about adding controls to main window
    By terracota in forum Windows Programming
    Replies: 4
    Last Post: 11-24-2004, 12:35 PM
  3. int main (), main (), main (void), int main (void) HELP!!!
    By SmokingMonkey in forum C++ Programming
    Replies: 7
    Last Post: 05-31-2003, 09:46 PM
  4. what to do with the main window
    By stallion in forum Windows Programming
    Replies: 2
    Last Post: 01-28-2003, 08:58 PM
  5. void or int for main?:)
    By bigtamscot in forum C Programming
    Replies: 13
    Last Post: 09-27-2001, 03:11 AM