[gnu.g++.lib.bug] compare.h bug

David.Detlefs@DLD.AVALON.CS.CMU.EDU (07/25/89)

Two bugs actually --

Using g++: 1.35
libg++: 1.35.1

First, I attempted to compile include.c, which only includes
compare.h, and got many errors of the form

In function int compare (short int, short int):
include.c:7: conflicting types for `int compare (short int, short int)'

These were fixed when I put an "overload compare;" at the top.  I
guess this is really a g++ error, and I'll report it there -- but I
want to know if my understanding that libg++-1.x should compile with
g++-1.x is wrong.

Second, and more serious: compare.h includes the definitions

--------------------------------------------------
inline int compare(float a, float b)
{
  return a - b;
}

inline int compare(double a, double b)
{
  return a - b;
}
--------------------------------------------------

These cause warnings when compiled, and it's a good thing: they're
just wrong.  For example,
  compare(0.5, 0.0);
returns 0 instead of a number > 0.

--------------------------------------------------
inline int compare(float a, float b)
{
  float x = a - b;
  return (x > 0.0 ? 1 : (x < 0.0 ? -1 : 0));
}

inline int compare(double a, double b)
{
  double x = a - b;
  return (x > 0.0 ? 1 : (x < 0.0 ? -1 : 0));
}
--------------------------------------------------

Dave