Look at my crappy program. Look at it!

This is a discussion on Look at my crappy program. Look at it! within the C Programming forums, part of the General Programming Boards category; Originally Posted by Hirumaru Oh, and a question. This is the basic purpose for creating a function, more or less, ...

  1. #16
    Captain Crash brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,239
    Quote Originally Posted by Hirumaru View Post
    Oh, and a question. This is the basic purpose for creating a function, more or less, right?
    We have functions for many reasons. If some chunk of code performs a well-defined task, placing it in a function can lead to clearer code. It allows us to reuse the code, if the same thing has to happen in more than one place. It allows us to provide a pointer to the function, which lets other code invoke our code even though it doesn't know anything about it. It also enables recursion, which would not be possible otherwise.
    Code:
    //try
    //{
    	if (a) do { f( b); } while(1);
    	else   do { f(!b); } while(1);
    //}

  2. #17
    Registered User
    Join Date
    Mar 2009
    Posts
    7
    That's kinda what I meant. You can't keep going back to main() for everything. Especially not so when your program has hundreds of lines of code and performs dozens of distinct operations.

    You need to be able to find, use, and reuse code efficiently. Otherwise your program'll get bottlenecked asking the same code for twenty different operations all at once.

    Heh. Programming is going to be so much fun. ^_^

    -Hiru

  3. #18
    Captain Crash brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,239
    Quote Originally Posted by Hirumaru View Post
    That's kinda what I meant. You can't keep going back to main() for everything. Especially not so when your program has hundreds of lines of code and performs dozens of distinct operations.
    You've grasped the point I think.

    Now, wait until you look at a multi-million line program I used to work on a codebase of 1.4 million lines. Now I only have to deal with 65 thousand lines, which seems small in comparison.
    Code:
    //try
    //{
    	if (a) do { f( b); } while(1);
    	else   do { f(!b); } while(1);
    //}

  4. #19
    Registered User
    Join Date
    Mar 2009
    Posts
    7
    Quote Originally Posted by brewbuck View Post
    Now, wait until you look at a multi-million line program .
    Just as long as I don't get eaten by an over-sized chicken like Dennis Nedry. @_@

    -Hiru

Page 2 of 2 FirstFirst 12
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Issue with program that's calling a function and has a loop
    By tigerfansince84 in forum C++ Programming
    Replies: 9
    Last Post: 11-12-2008, 12:38 PM
  2. Need help with a program, theres something in it for you
    By engstudent363 in forum C Programming
    Replies: 1
    Last Post: 02-29-2008, 12:41 PM
  3. Replies: 4
    Last Post: 02-21-2008, 09:39 AM
  4. My program, anyhelp
    By @licomb in forum C Programming
    Replies: 14
    Last Post: 08-14-2001, 10:04 PM

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