problem with cc compiler

Ari Halberstadt ari at eleazar.dartmouth.edu
Tue Jul 25 14:05:33 AEST 1989


In article <10599 at smoke.BRL.MIL> gwyn at brl.arpa (Doug Gwyn) writes:
>In article <4935 at alvin.mcnc.org> spl at mcnc.org.UUCP (Steve Lamont) writes:
>>Suppose that I wish to implement my own math library function, say sin() or
>>cos(), for whatever reason, in a large pre-existing piece of code that I don't
>>want to fiddle too much with.  How would I do this, then?
>Much better would be for you to name your functions my_cos() and my_sin(),
>and include something like the following in your application header file:
>        #undef cos      /* in case <math.h> uses a #define cos $$COS etc. */
>        #define cos     my_cos
>        #undef sin
>        #define sin     my_sin

I must voice a small criticism of the above scheme. By redefining a standard
function name, you may be greatly confusing any programmers who try
to read your code. These programmers will expect 
any standard named function to be IDENTICAL to the standard library function.
Unless you've completely debugged and tested it for compatability, they
won't know what hit them.
Also, what if someone copies your code without including the header file,
since they assumed it was not needed. Then, when they try to run it,
it won't perform!
I think there was another reason, but I can't remember it right now.
At any rate, I always opt for calling functions either "my_sin()",
or "xsin()". I use the second when I'm sick of seeing "my" all over
the place (for instance, on the Macintosh I replaced the standard
file package with my own mini-package, and prefixed all the standard
names with "x", to get "xfopen()", xgetc() "XFILE *", "xstdio.h", etc.)
On UNIX you can use the tools "ed" or "sed" (or awk if you want to
be fancy...) to change all the original function calls.
-- Ari Halberstadt '91, "Long live succinct signatures"
E-mail: ari at eleazar.dartmouth.edu	Telephone: (603)640-5687
Mailing address: HB1128, Dartmouth College, Hanover NH 03755



More information about the Comp.lang.c mailing list