473,805 Members | 2,191 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

finite() in ANSI C?

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.
Nov 14 '05 #1
11 14191
Nicholas R. Markham <ma*******@bigf oot.com> scribbled the following:
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 (pa*****@cc.hel sinki.fi) ------------- 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
Nov 14 '05 #2
"Nicholas R. Markham" <ma*******@bigf oot.com> writes:
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().

--
Brian Gough

Network Theory Ltd,
Publishing Free Software Manuals --- http://www.network-theory.co.uk/
Nov 14 '05 #3
Nicholas R. Markham wrote:
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).
Nov 14 '05 #4
In <cb***********@ newsfeeds.rpi.e du> "Nicholas R. Markham" <ma*******@bigf oot.com> writes:
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(.tex t+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
--
Dan Pop
DESY Zeuthen, RZ group
Email: Da*****@ifh.de
Nov 14 '05 #5
"Brian Gough" <bj*@network-theory.co.uk> wrote in message
news:87******** ****@network-theory.co.uk...
"Nicholas R. Markham" <ma*******@bigf oot.com> writes:
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().


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?
Nov 14 '05 #6
In <cb**********@n ewsfeeds.rpi.ed u> "Nicholas R. Markham" <ma*******@bigf oot.com> writes:
"Brian Gough" <bj*@network-theory.co.uk> wrote in message
news:87******* *****@network-theory.co.uk...
"Nicholas R. Markham" <ma*******@bigf oot.com> writes:
> 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 ifa > float or double is finite in ANSI C? Thanks.
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?


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
--
Dan Pop
DESY Zeuthen, RZ group
Email: Da*****@ifh.de
Nov 14 '05 #7
"Nicholas R. Markham" <ma*******@bigf oot.com> wrote:
"Brian Gough" <bj*@network-theory.co.uk> wrote:
"Nicholas R. Markham" <ma*******@bigf oot.com> writes:
> When I compile with the -ansi option (using gcc 3.2.3) I'm warned of an
> implicit declaration of function 'finite'.
<snip> 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?


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
--
Irrwahn Grausewitz (ir*******@free net.de)
welcome to clc: http://www.ungerhu.com/jxh/clc.welcome.txt
clc faq-list : http://www.faqs.org/faqs/C-faq/faq/
clc OT guide : http://benpfaff.org/writings/clc/off-topic.html
Nov 14 '05 #8
Nicholas R. Markham wrote:
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 <2j************ *@uni-berlin.de>
Nov 14 '05 #9
In <3v************ *************** *****@4ax.com> Irrwahn Grausewitz <ir*******@free net.de> writes:
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
--
Dan Pop
DESY Zeuthen, RZ group
Email: Da*****@ifh.de
Nov 14 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
2133
by: Hsuan-Yeh Chang | last post by:
Dear All, Anyone knows a good Finite Element Solver for python programer? Thanks! HYC
0
1300
by: Davide T | last post by:
How would I illustrate a finite state machine that checks that each start node/tag in an XML document has a corresponding end tag (ignoring nested tags of the same type and assuming that there is only a finite set of tags)?
100
7029
by: Roose | last post by:
Just to make a tangential point here, in case anyone new to C doesn't understand what all these flame wars are about. Shorthand title: "My boss would fire me if I wrote 100% ANSI C code" We are discussing whether this newsgroup should focus on 100% ANSI C or simply topics related to the C language in the real world. There is a C standard which is defined by an international committee. People who write compilers refer to this in...
3
6075
by: Babak | last post by:
Hello everyone, I'm working on some Finite Elements(FE) codes in C and now I encountered some problems in assembly stage. The main idea is that a large number of 3 by 3 elemental stiffness matrices are calculated and then they should mapped to specific elements in a very big and sparse global stiffness matrix. I think the preferred storage format for the sparse matrix is Compresses Row Storage (CRS) format because it is compatible with...
4
1926
by: onkar | last post by:
Can any one suggest me a game which uses FA as central concept and to be written in C.
67
7404
by: Rui Maciel | last post by:
I've been delving into finite state machines and at this time it seems that the best way to implement them is through an intense use of the goto statement. Yet, everyone plus their granmother is constantly cursing at the goto statement, accusing it of being some sort of spawn of satan. So it seems we have a pickle here. The thing is, at first thought it seems that there aren't any viable alternatives which are better suited for this...
127
5547
by: bz800k | last post by:
Hi Does this code satisfy ANSI C syntax ? void function(void) { int a = 2; a = ({int c; c = a + 2;}); /* <<-- here !! */ printf("a=%d\n", a);
0
10605
NeoPa
by: NeoPa | last post by:
ANSI-89 v ANSI-92 Before we get into all the various types of pattern matching that can be used, there are two ANSI standards used for the main types of wildcard matching (matching zero or more characters or simply matching a single character) : ANSI-89 - Mainly used only by Jet / ACE SQL ANSI-92 - Mainly used by SQL Server and other grown-up products In the later versions of Access it is now possible to select ANSI-92 compatibility as an...
41
3171
by: jaysome | last post by:
It's been almost eight years since ISO/IEC approved ISO/IEC 9899:1999. Does anyone know if ANSI has approved it? A Google search shows arguably confusing answers as to whether ANSI has approved it. For example, on this site: http://en.wikipedia.org/wiki/C_(programming_language)#ANSI_C_and_ISO_C it says that "It was adopted as an ANSI standard in March 2000."
0
9596
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10614
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10109
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9186
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7649
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6876
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5678
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4327
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3847
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.