开发者

How to pass data to many functions [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 12 years ago.

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.


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜