It depends on what size of code base you are having and how many people are maintaining it. If its a small code and only one person managing it, you can easily avoid functions. However, as the size of your code increases, there is an overhead to manage it. Lets say you have written a program to perform add/delete/remove node from linklist and everything is in main. Just try to answer how are you going to manage these operations, you will get to know the power of functions. It makes your code readable and bit easy to maintain.
~bharat ________________________________ From: shamir shakir <[email protected]> To: [email protected] Sent: Thu, March 4, 2010 12:13:40 PM Subject: [c-prog] Is this a good practise to call fuction ??? Hi Today I found a new (or probably) bad thing. I use to call fuction for anything I need. But It takes valuable time taking value and returning something. :( // This code describe how bad , calling fuction is... #include <stdio.h> #include <time.h> unsigned long int fuction(long long i) { // Do something ... return i ; } int main() { unsigned long long i; time_t end, start; start = clock() ; for(int i=0; i<1000; i++) for(int j=0; j<1000; j++) for(int k=0; k<1000; k++) ; end = clock() ; printf("IN MAIN FUNCTION ... \n ") ; printf("\t Total clock : %u \n", end-start) ; start = clock() ; for(int i=0; i<1000; i++) for(int j=0; j<1000; j++) for(int k=0; k<1000; k++) fuction(i) ; end = clock() ; printf("IN SUB FUNCTION .... \n") ; printf("\t Total clock : %u \n ", end-start ) ; printf("\nFunctions take a lot of time :( " ) ; return 0 ; } Now , I just want to know is this a good practice to work and utilize function calling? Or I'm just gonna work with main? -- Shamir Shakir Shishir http://DewsWorld. t35.com :::::....... ... Hope never ends........ ...::::: [Non-text portions of this message have been removed] [Non-text portions of this message have been removed]
