Compile error: function name collisions between port.h and math.h?

Anders F Björklund afb at algonet.se
Thu Apr 5 00:04:34 PDT 2007


mpb wrote:

> GCC (without D) compiles fine.  I'm running on Linux 2.6.12 with glibc
> 2.4 and compiling with GCC 4.1.1.

I haven't run into this issue before, strangely enough...
But looking at the header file, I can see how it can be.

They call three diffent lib functions, depending on the
sizeof of the actual argument, e.g. isnanf/isnan/isnanl

> port.h lines 37 through 40 are part of the declaration of struct Port:
> 
>     static int isnan(double);
>     static int isfinite(double);
>     static int isinfinity(double);
>     static int signbit(double);
> 
> It is interesting that line 39, while very similar, does not generate
> an error.

This is because there is no #define for isinfinity.

> The errors might be due to collisions with similarly named functions
> in math.h.

Similarly named *macros* that is, not functions...

> Any help resolving the problem would be appreciated.

At the top of port.h, it needs to include <math.h>
and then strip it from the use of any such macros:

#include <math.h>
#undef isnan
#undef isfinite
#undef signbit

If the code including "port.h" actually uses those,
it's possible to store them away and restore later:

#define OLD_foo	foo
#undef foo
...
#define foo OLD_foo

--anders


More information about the D.gnu mailing list