A tale of two C's.

00704a-Liber nevin1 at ihlpf.ATT.COM
Wed May 4 10:05:50 AEST 1988


In article <924 at cresswell.quintus.UUCP> ok at quintus.UUCP (Richard A. O'Keefe) writes:
>In article <488 at sas.UUCP>, bts at sas.UUCP (Brian T. Schellenberger) writes:
>> First of all, it is clearly unportable and dangerous to replace the versions
>> of the library routines used by other library routines...

>Sometimes that is exactly what you want.  For example, what is the good of
>replacing the malloc() family by something with the same interface but a
>much better implementation if this doesn't catch malloc() calls from stdio?

Suppose there are two routines: malloc() and _malloc().  malloc() is the
routine for heap allocation for both internal library calls and external
(programmer) calls.  _malloc() is strictly for internal library use only
(for example:  maybe malloc() does some checking of the heap while
_malloc() just does the allocating).

You come along and replace malloc() with your own function.  The library
routines that call malloc() are caught while the ones that call _malloc()
aren't.  There is no way for you to know whether or not you have replaced
_all_ the calls to the malloc family.

>A library _could_ be structured into "facilities" (malloc, stdio, math,
>signal&longjmp, ...) such that each facility was defined to use only the
>public interface of the other facilities.  It would then be safe to
>replace an entire facility with your own code.  There is nothing in the
>dpANS to prohibit a vendor doing this; code which relied on a well-structured
>library would be non-portable but no longer dangerous.

Yes, but there is nothing in dpANS which _requires_ this.  Nor do I think
it should be required.  If a compiler writer decides to hand code in
assembler all the library routines so that it produces the tightest,
fastest possible code he should be allowed to do so (in which case internal
subroutines may only be assembler JMP statements which do not have nearly
as much overhead as normal C function calls).

-- 
 _ __			NEVIN J. LIBER	..!ihnp4!ihlpf!nevin1	(312) 510-6194
' )  )				"The secret compartment of my ring I fill
 /  / _ , __o  ____		 with an Underdog super-energy pill."
/  (_</_\/ <__/ / <_	These are solely MY opinions, not AT&T's, blah blah blah



More information about the Comp.lang.c mailing list