views:

74

answers:

2

I am new to C++ programming.

Now I have a program that consists of millions of lines of code in thousands of files. But when I saw the main() (command line) it was very small. Now how to pass data to so many million functions from such a small main()? There was no text file for parsing or array of structure that contains a function pointer and a text string etc.

+3  A: 

Imagine I have a fifty-thousand-line-long function, called foo(). Now let's say I write a main function that's one line long, and just calls foo(). I still have fifty thousand lines of code, but main is tiny.

Or let's say I have fifty thousand two-line long functions. Each one consists of calls to two others. If main calls one of them, it's possible that all of them will get called at some point. That's over a hundred thousand lines of code, with fifty thousand and one functions, and none of the functions are longer than two lines.

The size of main means nothing.

Borealid
+1 for saying that the size of `main` means nothing. Even most girls say size doesn't matter !
ereOn
To my knowledge the two cases do not apply in real world programming.I have a GUI library and an application from it that contains over a million functions. Now how can I pass data to so many of them? The program is running without any compiler errors.
Supriyo
+1  A: 

First, in a well designed program, there are many small functions. Each of the functions do a small thing and let some other function do the real work.

Second, if a parameter is a struct or an array, it can contain a lot of data. A small number of parameters do not always indicate that little data is passed.

For example, your main() function may look like this:

int main(int argc, char ** argv) {
    options programOptions;
    work result;

    programOptions = parseOptions(argv);
    result = doTheWork(programOptions);
    printResult(result);
}

It is hard to tell more without some code or an example what your program does.

Sjoerd