Expert C Programming

(Jeff_L) #1

particular program, usually for debugging or performance reasons. But like a gun with no safety catch,
while it lets experts get faster results, it also makes it very easy for novices to hurt themselves.


Interpositioning requires great care. It's all too easy to do this accidentally and replace a symbol in a
library by a different definition in your own code. Not only are all the calls that you make to the
library routine replaced by calls to your version, but all calls from system routines now reference your
routine instead. A compiler will typically not issue an error message when it notices a redefinition of a
library routine. In keeping with C's philosophy that the programmer is always right, it assumes the
programmer meant to do it.


Over the years we have seen no convincing examples where interpositioning was essential but the
effect could not be obtained in a different (perhaps less convenient) manner. We have seen many
instances where a default global scope symbol combined with interpositioning to create a hard-to-find
bug (see Figure 5-3). We have seen a dozen or so bug reports and emergency problem escalations
from even the most knowledgeable software developers. Unhappily, it's not a bug; the implementation
is supposed to work this way.


Figure 5-3. Diagram of Interpositioning and Default Global Scope
Free download pdf