finite() in ANSI C?

  • Thread starter Nicholas R. Markham
  • Start date
N

Nicholas R. Markham

When I compile with the -ansi option (using gcc 3.2.3) I'm warned of an
implicit declaration of function 'finite'. Does this mean that finite() is
not part of ANSI C, or that I didn't include a necessary header file? (I
did include math.h.) Either way, is there a recommended way to check if a
float or double is finite in ANSI C? Thanks.
 
J

Joona I Palaste

Nicholas R. Markham said:
When I compile with the -ansi option (using gcc 3.2.3) I'm warned of an
implicit declaration of function 'finite'. Does this mean that finite() is
not part of ANSI C, or that I didn't include a necessary header file? (I
did include math.h.) Either way, is there a recommended way to check if a
float or double is finite in ANSI C? Thanks.

finite() is not part of ANSI C.

--
/-- Joona Palaste ([email protected]) ------------- Finland --------\
\-- http://www.helsinki.fi/~palaste --------------------- rules! --------/
"'So called' means: 'There is a long explanation for this, but I have no
time to explain it here.'"
- JIPsoft
 
B

Brian Gough

Nicholas R. Markham said:
When I compile with the -ansi option (using gcc 3.2.3) I'm warned of an
implicit declaration of function 'finite'. Does this mean that finite() is
not part of ANSI C, or that I didn't include a necessary header file? (I
did include math.h.) Either way, is there a recommended way to check if a
float or double is finite in ANSI C? Thanks.

finite() is from BSD. The equivalent in C99 is isfinite().
 
M

Martin Ambuhl

Nicholas said:
When I compile with the -ansi option (using gcc 3.2.3) I'm warned of an
implicit declaration of function 'finite'. Does this mean that finite() is
not part of ANSI C, or that I didn't include a necessary header file? (I
did include math.h.) Either way, is there a recommended way to check if a
float or double is finite in ANSI C? Thanks.
The headers (in particular <math.h>) in your implementation will show
some things which are in C99 but not in C89 hidden within #ifdefs
designed to make them invisible with C89. Just move them outside the
#ifdefs. This does not solve the problem of things missing completely
from the headers (and perhaps from the libraries).
 
D

Dan Pop

In said:
When I compile with the -ansi option (using gcc 3.2.3) I'm warned of an
implicit declaration of function 'finite'. Does this mean that finite() is
not part of ANSI C, or that I didn't include a necessary header file? (I
did include math.h.) Either way, is there a recommended way to check if a
float or double is finite in ANSI C? Thanks.

C89 provides no support for the IEEE-754 gadgets and the effect of -ansi
is to remove all the extensions declared in the standard headers.

C99 does provide support for all the IEEE-754 stuff, but the name of the
thing is isfinite and it is a macro (defined in math.h). If your math.h
has it, you may have to enable it using the -std=c99 option:

fangorn:~/tmp 30> cat test.c
#include <math.h>

int main()
{
return !isfinite(1);
}
fangorn:~/tmp 31> gcc test.c
/tmp/ccwzl0tE.o(.text+0x18): In function `main':
: undefined reference to `isfinite'
collect2: ld returned 1 exit status
fangorn:~/tmp 32> gcc -std=c99 test.c
fangorn:~/tmp 33> ./a.out
fangorn:~/tmp 34> echo $status
0

Dan
 
N

Nicholas R. Markham

Brian Gough said:
finite() is from BSD. The equivalent in C99 is isfinite().

So since finite() is not part of any standard, I probably shouldn't be using
it. But:

- isfinite() is in C99 but not C89; it's an improvement, but wouldn't I be
better off to stick with C89, to maximize portability?

- when I try to use isfinite() on a Solaris machine with gcc 3.3, including
the math.h header, linking with the math library and specifying -std=c99, I
still get an implicit declaration warning. Shouldn't that work?
 
D

Dan Pop

In said:
So since finite() is not part of any standard, I probably shouldn't be using
it. But:

- isfinite() is in C99 but not C89; it's an improvement, but wouldn't I be
better off to stick with C89, to maximize portability?

In which case, there is NO way to test whether a value is finite or not.
Portable C code cannot even assume the existence of Inf's.
- when I try to use isfinite() on a Solaris machine with gcc 3.3, including
the math.h header, linking with the math library and specifying -std=c99, I
still get an implicit declaration warning. Shouldn't that work?

Keep in mind that gcc is only a compiler. If the headers and libraries
provided by Solaris do not claim full C99 support, you have no good
reason to expect isfinite() to be available.

Dan
 
I

Irrwahn Grausewitz

Nicholas R. Markham said:
So since finite() is not part of any standard, I probably shouldn't be using
it. But:

- isfinite() is in C99 but not C89; it's an improvement, but wouldn't I be
better off to stick with C89, to maximize portability?

It would. But you have to provide your own implementation of
isfinite, of course.
- when I try to use isfinite() on a Solaris machine with gcc 3.3, including
the math.h header, linking with the math library and specifying -std=c99, I
still get an implicit declaration warning. Shouldn't that work?

Smells like a broken (read: incomplete) library implementation.
<OT> It works correctly with the mingw port of gcc 3.3.1. </OT>

Regards
 
D

Dan Pop

In said:
Smells like a broken (read: incomplete) library implementation.

Merely like an implementation that doesn't claim C99 conformance.
<OT> It works correctly with the mingw port of gcc 3.3.1. </OT>

I doubt that the mingw port of gcc 3.3.1 comes with conforming C99
libraries. So, your example is not only off topic, but also irrelevant.

Dan
 
M

Martin Ambuhl

Nicholas said:
So since finite() is not part of any standard, I probably shouldn't be using
it. But:

- isfinite() is in C99 but not C89; it's an improvement, but wouldn't I be
better off to stick with C89, to maximize portability?

- when I try to use isfinite() on a Solaris machine with gcc 3.3, including
the math.h header, linking with the math library and specifying -std=c99, I
still get an implicit declaration warning. Shouldn't that work?

Please read my earlier post <[email protected]>
 
I

Irrwahn Grausewitz

Merely like an implementation that doesn't claim C99 conformance.

An incomplete library implementation implies non-conformance (for a
hosted implementation, that is). I did not feel compelled to point
that out explicitly.

I doubt that the mingw port of gcc 3.3.1 comes with conforming C99
libraries.

Nobody claimed that it does. The isfinite macro however /is/
implemented, and AFAICT it works correctly. Alas, it's entirely
possible that I can't tell far enough.
So, your example is not only off topic, but also irrelevant.

Off topic contributions are irrelevant per definitionem.

Regards
 
D

Dan Pop

In said:
Off topic contributions are irrelevant per definitionem.

If they were, most people wouldn't make them in the first place. They
might be irrelevant to the topic of the newsgroup, but they are supposed
to be relevant to the actual discussion. Consider, for example, people
posting the diagnostics generated by one compiler or another when
translating the code being discussed. Or descriptions of how a certain
(real or hypothetical) implementation would handle a certain code
snippet.

Dan
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,143
Messages
2,570,822
Members
47,368
Latest member
michaelsmithh

Latest Threads

Top