Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!ncar!asuvax!noao!arizona!sunquest!ggg From: ggg@sunquest.UUCP (Guy Greenwald) Newsgroups: comp.lang.c Subject: Re: problem with cc compiler Summary: Glad to see you're still teaching, Robert Message-ID: <177@sunquest.UUCP> Date: 28 Jul 89 00:03:11 GMT References: <712@unsvax.NEVADA.EDU> <10589@smoke.BRL.MIL> <4935@alvin.mcnc.org> <12911@megaron.arizona.edu> Organization: Sunquest Information Systems, Tucson Lines: 67 In article <12911@megaron.arizona.edu>, robert@arizona.edu (Robert J. Drabek) writes: > 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 and I worked together once. We spent a lot of our time arguing, but eventually it got too personal for me. I just can't resist answering this time, but as Robert points out, there are more interesting topics than this one. He'll have the last word. I agree with your first point. A static declaration would be more consistent. However, neither the UNIX C compiler on our Sun nor the VMS C compiler on our MicroVAX complained. There was not a peep from lint, either. You claim that if math.h is included, the problem isn't solved. I tested the following piece of code on both systems mentioned above: #include #include main() { double sin(); (void) printf("%f\n", sin(.7)); } static double sin(angle) double angle; { return angle; } In both cases, the value 0.700000 was printed. Did I miss something here? It sure seemed like the linker did what I thought it would. Perhaps you have a piece of code that proves the VMS linker chooses the RTL and the UNIX linker doesn't. What did I miss? As to your last two points, I agree. Better to avoid the problem in the first place by selecting names more carefully. I also like the #define. Thanks for the ideas.