Wednesday 16 November 2011

Can multiple library functions be included in the same source file? in C programming

Can multiple library functions be included in the same source file?

You can define as many functions as you want in the same source file and still include them in a library— however, this technique has serious disadvantages when it comes to linking your programs and sharing source files in a team development environment.

When you include more than one library function in the same source file, the functions are compiled into the same object (.obj) file. When the linker links one of these functions into your program, all the functions in the object file are pulled in—whether or not they are used in your program. If these functions are unrelated (do not have calls to each other within their definitions), you will be wasting precious program space by pulling unneeded code. See FAQ XVIII.7 for an example. This is one reason why it is better to put library functions in their own separate source files.

Another good reason to put library functions in their own source files is for code sharing in a team development environment. Using separate source files enables programmers to check out and check in
individual functions, instead of locking others out of being able to make changes to several functions contained in one source file.

Cross Reference:

XVIII.7: Are all the functions in a library added to an .EXE file when the library is linked to the
objects?
XVIII.9: Why should I create a library?
XVIII.9: Why should I create a library

No comments:

Post a Comment