版本3和4间的区别
于2007-07-18 19:50:15修订的的版本3
大小: 1669
编辑: czk
备注:
于2007-07-18 19:57:58修订的的版本4
大小: 1637
编辑: 125
备注:
删除的内容标记成这样。 加入的内容标记成这样。
行号 10: 行号 10:
attachment:Functions_and_Program_Structure/pic41.gif attachment:pic41.gif

Navigation(slides)

4.5 Header Files

Let is now consider dividing the calculator program into several source files, as it might be is each of the components were substantially bigger. The main function would go in one file, which we will call main.c; push, pop, and their variables go into a second file, stack.c; getop goes into a third, getop.c. Finally, getch and ungetch go into a fourth file, getch.c; we separate them from the others because they would come from a separately-compiled library in a realistic program.

There is one more thing to worry about - the definitions and declarations shared among files. As much as possible, we want to centralize this, so that there is only one copy to get and keep right as the program evolves. Accordingly, we will place this common material in a header file, calc.h, which will be included as necessary. (The #include line is described in Section 4.11.) The resulting program then looks like this:

attachment:pic41.gif

There is a tradeoff between the desire that each file have access only to the information it needs for its job and the practical reality that it is harder to maintain more header files. Up to some moderate program size, it is probably best to have one header file that contains everything that is to be shared between any two parts of the program; that is the decision we made here. For a much larger program, more organization and more headers would be needed.

Navigation(siblings)

TCPL/4.05_Header_Files (2008-02-23 15:35:36由localhost编辑)

ch3n2k.com | Copyright (c) 2004-2020 czk.