[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: C, math.h and globals



On Tue, Mar 11, 2003 at 10:39:31AM +0100, Sebastiaan wrote:
> I have an odd thing with the math library and C. Take this simple program
> as example:
> 
> #include <math.h>
> 
> double	y1;
> int main(void)
> {
> 	return 0;
> }
> 
> 
> When I try to compile this (just 'gcc test.c'), the compiler returns me
> this error:
> 
> test.c:4: `y1' redeclared as different kind of symbol
> /usr/include/bits/mathcalls.h:242: previous declaration of `y1'
> 
> 
> I know that you should try to declare as few globals as possible, but I
> had to compile a program with this issue from a friend (who runs windoze).
> 
> Isn't this a bug in the C library? I mean, the standard libraries ought
> not to be interfering with the variables you choose?

Well, y1() is specified as a mathematical function in SUSv2
(http://www.opengroup.org/onlinepubs/007908799/xsh/y0.html) and SUSv3
(http://www.opengroup.org/onlinepubs/007904975/functions/y0.html); I
think it predates those standards too. So this is a standard function
that applications should steer clear of.

You could '#define __STRICT_ANSI__' at the top of the program if you
want the C library to define only what's in bare ISO Standard C, or
'#define _ISOC99_SOURCE' for C99. With either of those y1() won't be
defined.

-- 
Colin Watson                                  [cjwatson@flatline.org.uk]



Reply to: