Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!purdue!bu-cs!dartvax!eleazar.dartmouth.edu!ari From: ari@eleazar.dartmouth.edu (Ari Halberstadt) Newsgroups: comp.lang.c Subject: Re: problem with cc compiler Message-ID: <14631@dartvax.Dartmouth.EDU> Date: 25 Jul 89 04:05:33 GMT References: <712@unsvax.NEVADA.EDU> <10589@smoke.BRL.MIL> <1185@fcs280s.ncifcrf.gov> <10594@smoke.BRL.MIL> <4935@alvin.mcnc.org> <10599@smoke.BRL.MIL> Sender: news@dartvax.Dartmouth.EDU Reply-To: ari@eleazar.dartmouth.edu (Ari Halberstadt) Organization: Dartmouth College, Hanover, NH Lines: 32 In article <10599@smoke.BRL.MIL> gwyn@brl.arpa (Doug Gwyn) writes: >In article <4935@alvin.mcnc.org> spl@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 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@eleazar.dartmouth.edu Telephone: (603)640-5687 Mailing address: HB1128, Dartmouth College, Hanover NH 03755