problem with cc compiler
Guy Greenwald
ggg at sunquest.UUCP
Fri Jul 28 10:03:11 AEST 1989
In article <12911 at megaron.arizona.edu>, robert at 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 <math.h> 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 <stdio.h>
#include <math.h>
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.
More information about the Comp.lang.c
mailing list