From: Hans-Bernhard Broeker Newsgroups: comp.os.msdos.djgpp Subject: Re: question about linker behaviour Date: 2 Oct 2000 11:59:53 GMT Organization: Aachen University of Technology (RWTH) Lines: 33 Message-ID: <8r9tbp$ffl$1@nets3.rz.RWTH-Aachen.DE> References: <39D546B8 DOT 2310 AT home DOT com> NNTP-Posting-Host: acp3bf.physik.rwth-aachen.de X-Trace: nets3.rz.RWTH-Aachen.DE 970487993 15861 137.226.32.75 (2 Oct 2000 11:59:53 GMT) X-Complaints-To: abuse AT rwth-aachen DOT de NNTP-Posting-Date: 2 Oct 2000 11:59:53 GMT Originator: broeker@ To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Reply-To: djgpp AT delorie DOT com Salvador I. Ducros wrote: > My question is basically whether or not the linker (let's say > the DJGPP linker specifically) will include a function from a static > library into an executable if: > 1. the address of the function is assigned to some function pointer > 2. the function pointer is never actually derefernced > 3. the function is never called by name It's not the linker's decision alone that determines this. Actually, the key decision is made by the *compiler* of the code that does the function pointer assignment and usage. Only the compiler has the necessary information to be able to detect clause 2. (that the function pointers are never dereferenced). Even then, it usually will *not* take the consequence and omit their initialisations (clause 1.). The fact that in your case the function pointers are part of a *struct* makes it even less likely that the compiler will optimize their initialization away. For a standalone function pointer variable, the compiler could detect that it's unused (and warn about that), and in consequence optimize it out of existence. With the function pointer not existing any more, the linker would have no reason left to suspect that the function might be needed. As long as the initialisations are done in the compiled code, there's absolutely no way the linker could be allowed to not draw the pointed-to functions into the executable. -- Hans-Bernhard Broeker (broeker AT physik DOT rwth-aachen DOT de) Even if all the snow were burnt, ashes would remain.