Mailing Lists: Apple Mailing Lists
Image of Mac OS face in stamp
Re: problems with C++ on OS X (re: isnan and isinf)
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: problems with C++ on OS X (re: isnan and isinf)



Yes, they are defined, but they don't work (which is
an important difference), and so the following code
always fails with g++3:
in isnan.cc:
#include<cmath>
#include<iostream>
#include<cstdlib>
using namespace std;

int main(int arg,char *argv[])
{
double x = 0.;
double y = 0.;
if (isnan(x/y))
{
cout << "division by zero results in
nan"<<endl;
}
else if (isinf(x/y))
{
cout << "division by zero results in
inf"<<endl;
}
}

g++3 isnan.cc fails with:
isnan.cc: In function `int main(int, char**)':
isnan.cc:10: `isnan' undeclared (first use this
function)
isnan.cc:10: (Each undeclared identifier is reported
only once for each
function it appears in.)
isnan.cc:14: `isinf' undeclared (first use this
function)

where as g++2 works just fine.

Also, here is what apple has to say about it:

=================================================================
THE INFORMATION CONTAINED IN THIS MESSAGE IS UNDER
NONDISCLOSURE.
==================================================================
6G30 c++ header cmath fails to define certain
functions
Bug ID # 3147992

Hello Kevin,

Thank you for bringing this issue to our attention.
This is a known issue
that is currently being investigated by engineering.
This issue has been filed in our bug database under ID
# 3032867.

The reason for the bug is that these fxns are macros
in C, and are undef'd and replaced with templaces in
standard C++ (hence all the #undef's in the header you
refer to). The problem is, they are never properly
redefined in namepsace std, leadint to compiler error.
The problem can be solved by commenting out the
undefs in <cmath>, but editing standard headers is bad
behavior in general. Also, editing the header simply
puts the C macros in the global namespace (IIRC),
meaning that the distinction between cmath and math.h
is only in the 2 different characters you have to
type.

--Kevin
>hmm..
> isnan() and isinf() *are* defined in
>/usr/include/gcc/darwin/3.1/g++-v3/cmath
>
> Yarden

=====
Kevin Thornton
Committee on Genetics
University of Chicago
http://www.molpopgen.org
Yahoo! Mail Plus - Powerful. Affordable. Sign up now.
http://mailplus.yahoo.com
_______________________________________________
darwin-development mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/darwin-development
Do not post admin requests to the list. They will be ignored.



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2011 Apple Inc. All rights reserved.