Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!bloom-beacon!bu-cs!encore!cloud9!dts From: dts@cloud9.Stratus.COM (Daniel Senie) Newsgroups: comp.sys.ibm.pc Subject: Re: Turbo C links in everything in obj's Summary: Useful for debugging Message-ID: <4514@cloud9.Stratus.COM> Date: 25 Mar 89 01:08:18 GMT References: <7337@phoenix.Princeton.EDU> <319@cbnewsc.ATT.COM> Organization: Stratus Computer, Inc., Marlboro, MA Lines: 37 In article <319@cbnewsc.ATT.COM>, tjr@cbnewsc.ATT.COM (thomas.j.roberts) writes: > > In article <1065@ptolemy.arc.nasa.gov> raymond@ptolemy.arc.nasa.gov > > (Eric A. Raymond) writes: > >>It appears that the linker in Turbo C (2.0) links in everything you > >>have in your .objs independent of whether the code is actually used. > >>For instance, if you have a file with the following fn's in it > >> main, a, b, c, d, e > >>and main does not call any of a, b, c, d, or e, the linker still > >>includes the objects for a, b, c, d, and e. > > This is, of course, required by the definition of the C language; it is NOT > a disadvantage of Turbo C. In C, files are always linked in in their > entirety. tlink also links in a .obj that is named on the command line, > whether or not ANY of its functions are called elsewhere; I presume that > is to avoid an extra pass during linking to specifically check for an > un-referenced .obj file. > There is a very good use for linking in an obj file which is not directly connected with your program. You can, using TurboDebugger invoke a subroutine at any point. Using a function which is linked in but not called could be used for dumping a particularly unusual data structure, or verifying such. Library files, as noted by several posters, is the proper way to control inclusion in executables. Linkers glue together whatever you tell them to. Then they look for unresolved references. Note that it is a good idea to limit the number of functions per object module which is incorporated into a LIB file, as this helps keep the size of your programs down. -- Daniel Senie UUCP: harvard!ulowell!cloud9!dts Stratus Computer, Inc. ARPA: anvil!cloud9!dts@harvard.harvard.edu 55 Fairbanks Blvd. CSRV: 74176,1347 Marlboro, MA 01752 TEL.: 508 - 460 - 2686