Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!csd4.milw.wisc.edu!bionet!ig!arizona!robert From: robert@arizona.edu (Robert J. Drabek) Newsgroups: comp.lang.c Subject: Re: problem with cc compiler Summary: pointer to error Message-ID: <12911@megaron.arizona.edu> Date: 27 Jul 89 21:30:13 GMT References: <712@unsvax.NEVADA.EDU> <10589@smoke.BRL.MIL> <4935@alvin.mcnc.org> <175@sunquest.UUCP> Organization: U of Arizona CS Dept, Tucson Lines: 58 In article <175@sunquest.UUCP>, ggg@sunquest.UUCP (Guy Greenwald) writes: > In article <4935@alvin.mcnc.org>, spl@mcnc.org (Steve Lamont) writes: > > Suppose that I wish to implement my own math library function, say sin() > > Declare the routine name before it is invoked, then define the routine to be > static. Here's an example: > > main() > { > double sin(); > x = sin(something); > } > > static double sin(angle) > double angle; > { > /* Steve's slick sine calculation */ > } > > It is the combination of the static definition and the declaration before use > that avoids the problem with the duplicate name in the run-time library. Sigh. First, Guy specifies (by default) external linkage for the function and then later declares it to be static. A good compiler should complain about this disparity in storage classes. Simply placing "static" at the beginning of the first declaration could solve that. BUT since the original poster talked about large existing code, we would want to be careful about the possibility of already being included. So, we still haven't solved it. Most importantly, though, is what happens during linking? Try it in various environments and you will find that sometimes it links with the library sin() [VMS] and sometimes with your own [Unix cc]. The linker probably doesn't care about your declarations. (Try Ada if you really want that.) Name space problems have been around since before computers, and we simply carried them along to this new domain. What is wrong with creating a name for your new sine function which has a lower probability of conflict (letting you get on to more interesting topics) when you don't want to replace the library function? If you really want to replace calls to such "standard" functions with calls to your own, I don't think you will find a universal method using the compiler and linker proper. The preprocessor, though, could be used with something like maybe #define sin(x) my_sin(x) -- Robert J. Drabek Department of Computer Science The University of Arizona Tucson, AZ 85721