Mail Archives: djgpp/2000/10/02/08:53:49
Salvador I. Ducros <sducros AT home DOT com> 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.
- Raw text -