C++ header file problem - is this a bug?

Dave Korn dave.korn@artimi.com
Tue Jan 4 19:31:00 GMT 2005


> -----Original Message-----
> From: Bill Northcott 
> Sent: 04 January 2005 18:57

> Sorry I don't get that.  Where is the bug in the following code?
> #include <iostream>
> #include <math.h>
> isnan(x);

  Well, the fact is that you haven't defined x, and the call to isnan isn't in a
function, so basically that's gibberish; your use of isnan there looks like a
malformed prototype.

  However, the bug is not in the code as such, but in your misunderstanding of
what is supposed to happen.  That code would compile and work correctly if you
had actually put that call to isnan in a function.  The bug is in your mistaken
belief that isnan has to be a macro.
 
> isnan() is a macro defined in math.h, but it does not work in this 
> snippet.  How do you suggest this code is 'fixed'??

  Did you notice that you're writing C++, and ***NOT*** C?

  As such, you should use the C++ library functions and headers, not the C
library functions and headers, since they're for a different programming
language.

  Why aren't you using the std::isnan() function?

> As discussed in PR14608 the bug is in gcc.

  No, as explained in PR14608 in comment #4 by GDR, this is the correct
behaviour and not a bug at all.

>  Various macros in math.h 
> don't work if cmath.h also gets included.

  The C++ language standard *explicitly forbids* the importing of those macros
from old C header files.  Gcc is doing *exactly* the correct thing.

>  It comes up with all sorts of code on different platforms.

  There is lots of invalid code out there written by people who don't understand
the tools they're using or the language they're coding in.  That still doesn't
make gcc buggy.

    cheers, 
      DaveK
-- 
Can't think of a witty .sigline today....



More information about the Gcc mailing list