473,785 Members | 2,761 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

compile detection of powf, etc

Is there a standard way using the preprocessor to detect if a given C
compiler/library environment provides the C99 <math.h> floating point
functions such as:

float powf(float x, float y);
float sqrtf(float x);
etc

so we could "provide" these prototypes or not via our

"xtra_math. h" file

Note some C environments are incomplete and may define the C90 flag but
still provide these functions. So I think we need to check each
function.

looking for any suggestions

thanks

Jan 30 '06 #1
11 2781
In article <11************ **********@g47g 2000cwa.googleg roups.com>,
Marco <pr**********@y ahoo.com> wrote:
Is there a standard way using the preprocessor to detect if a given C
compiler/library environment provides the C99 <math.h> floating point
functions such as: float powf(float x, float y);
float sqrtf(float x); Note some C environments are incomplete and may define the C90 flag but
still provide these functions. So I think we need to check each
function.
C90 does not define any feature-test preprocessor variables,
so any such macro provided by an environment intermediate between C90
and C99 is, by definition, non-standard.

If you need to be able to determine the presence or absence of
particular routines, I suggest you consider using something like
"automake".

so we could "provide" these prototypes or not via our
"xtra_math. h" file


That hints at a commercial product; if so then if you do look at
automake, ensure that you read the accompanying licenses.
--
All is vanity. -- Ecclesiastes
Jan 30 '06 #2


Marco wrote On 01/30/06 10:21,:
Is there a standard way using the preprocessor to detect if a given C
compiler/library environment provides the C99 <math.h> floating point
functions such as:

float powf(float x, float y);
float sqrtf(float x);
etc

so we could "provide" these prototypes or not via our

"xtra_math. h" file

Note some C environments are incomplete and may define the C90 flag but
still provide these functions. So I think we need to check each
function.


`#if __STDC_VERSION_ _ >= 199901L' tests whether the
implementation claims to conform to C99; if it does, the
functions you're looking for are present.

I can think of no portable way to tell whether these
functions exist as extensions in earlier implementations .
You could use `#ifdef powf' to check for a "masking" macro
and assume that the corresponding function exists if the
macro is defined, but the function might also exist without
a masking macro. You may simply need to tailor your
"xtra_math. h" header to each implementation you care about,
possibly with a semi-automated tool like autoconf.

--
Er*********@sun .com

Jan 30 '06 #3
On 2006-01-30, Marco <pr**********@y ahoo.com> wrote:
Is there a standard way using the preprocessor to detect if a given C
compiler/library environment provides the C99 <math.h> floating point
functions such as:

float powf(float x, float y);
float sqrtf(float x);
etc

so we could "provide" these prototypes or not via our

"xtra_math. h" file

Note some C environments are incomplete and may define the C90 flag but
still provide these functions. So I think we need to check each
function.

looking for any suggestions

thanks


(semi-offtopic)
One way [this is highly system-specific - basically unix-only, and may
not be guaranteed even by the POSIX standard] would be to provide the
functions in a static library and link it after libm. If the link editor
finds it in libm, it won't take the one from your library.
static library
Jan 30 '06 #4
Eric Sosman <er*********@su n.com> writes:
Marco wrote On 01/30/06 10:21,:
Is there a standard way using the preprocessor to detect if a given C
compiler/library environment provides the C99 <math.h> floating point
functions such as:

float powf(float x, float y);
float sqrtf(float x);
etc

so we could "provide" these prototypes or not via our

"xtra_math. h" file

Note some C environments are incomplete and may define the C90 flag but
still provide these functions. So I think we need to check each
function.
`#if __STDC_VERSION_ _ >= 199901L' tests whether the
implementation claims to conform to C99; if it does, the
functions you're looking for are present.


It means that the compiler *claims* to conform to C99. If it's lying,
then it's not a conforming C compiler, and the requirements of the C
standard don't apply to it.

The compiler might not actually know whether the functions are
available. The compiler and the library are commonly separate (for
example, gcc uses whatever library is provided by the underlying
system). If the compiler is conforming and the library isn't, the
compiler *shouldn't* define __STDC_VERSION_ _ as 199901L, but it might
do so anyway.
I can think of no portable way to tell whether these
functions exist as extensions in earlier implementations .
You could use `#ifdef powf' to check for a "masking" macro
and assume that the corresponding function exists if the
macro is defined, but the function might also exist without
a masking macro. You may simply need to tailor your
"xtra_math. h" header to each implementation you care about,
possibly with a semi-automated tool like autoconf.


Or you can write a simple test as part of your build process. Try to
compile and execute a small program that uses the functions. If it
produces the expected output, you can use <math.h>; if not, you need
to use "xtra_math. h". You can generate a header file at build time,
and include the generated header in your actual program.

This is basically what autoconf does, but if this is the only test you
need it might be simpler to do it manually.

--
Keith Thompson (The_Other_Keit h) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Jan 30 '06 #5


Keith Thompson wrote On 01/30/06 14:29,:
Eric Sosman <er*********@su n.com> writes:
Marco wrote On 01/30/06 10:21,:
Is there a standard way using the preprocessor to detect if a given C
compiler/library environment provides the C99 <math.h> floating point
functions such as:

float powf(float x, float y);
float sqrtf(float x);
etc

so we could "provide" these prototypes or not via our

"xtra_math. h" file

Note some C environments are incomplete and may define the C90 flag but
still provide these functions. So I think we need to check each
function.
`#if __STDC_VERSION_ _ >= 199901L' tests whether the
implementatio n claims to conform to C99; if it does, the
functions you're looking for are present.

It means that the compiler *claims* to conform to C99. If it's lying,
then it's not a conforming C compiler, and the requirements of the C
standard don't apply to it.


That's more or less why I wrote "claims" to begin with.
The compiler might not actually know whether the functions are
available. The compiler and the library are commonly separate (for
example, gcc uses whatever library is provided by the underlying
system). If the compiler is conforming and the library isn't, the
compiler *shouldn't* define __STDC_VERSION_ _ as 199901L, but it might
do so anyway.


If the compiler lies to me, I will get my revenge ;-)
My only vehicle for vendetta may be to demand my money back
and to bad-mouth the vendor in every forum I can find, but
somehow I will get my revenge. Mwa-ha-haaah!

Note that the compiler and library are not separable
(in hosted implementations ): Both are simply parts of "the
implementation" as far as the Standard is concerned. Thus,
__STDC_VERSION_ _ (and indeed, __STDC__ itself) assert things
not only about the compiler but also about the library and
about support routines that take care of things like opening
stdin before main() is called. All the pieces must cooperate;
it invites error to try to isolate them.

--
Er*********@sun .com

Jan 30 '06 #6
Eric Sosman <er*********@su n.com> writes:
[...]
If the compiler lies to me, I will get my revenge ;-)
My only vehicle for vendetta may be to demand my money back
and to bad-mouth the vendor in every forum I can find, but
somehow I will get my revenge. Mwa-ha-haaah!

Note that the compiler and library are not separable
(in hosted implementations ): Both are simply parts of "the
implementation" as far as the Standard is concerned. Thus,
__STDC_VERSION_ _ (and indeed, __STDC__ itself) assert things
not only about the compiler but also about the library and
about support routines that take care of things like opening
stdin before main() is called. All the pieces must cooperate;
it invites error to try to isolate them.


As far as the standard is concerned, yes. But there *are* cases where
the compiler and library are implemented separately. The compiler is
responsible for defining __STD__ and __STDC_VERSION_ _ appropriately to
reflect the conformance of the implementation as a whole. Whether all
compilers actually do this properly is another question.

I have seen cases (not necessarily tied to library issues) where a
compiler's definition of __STDC__ was inconsistent with reality.
There's not a whole lot you can do to defend against that, other than
thorough testing.

--
Keith Thompson (The_Other_Keit h) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Jan 30 '06 #7
On Mon, 30 Jan 2006 19:29:04 GMT, Keith Thompson <ks***@mib.or g> wrote
in comp.lang.c:
Eric Sosman <er*********@su n.com> writes:
Marco wrote On 01/30/06 10:21,:
Is there a standard way using the preprocessor to detect if a given C
compiler/library environment provides the C99 <math.h> floating point
functions such as:

float powf(float x, float y);
float sqrtf(float x);
etc

so we could "provide" these prototypes or not via our

"xtra_math. h" file

Note some C environments are incomplete and may define the C90 flag but
still provide these functions. So I think we need to check each
function.


`#if __STDC_VERSION_ _ >= 199901L' tests whether the
implementation claims to conform to C99; if it does, the
functions you're looking for are present.


It means that the compiler *claims* to conform to C99. If it's lying,
then it's not a conforming C compiler, and the requirements of the C
standard don't apply to it.

The compiler might not actually know whether the functions are
available. The compiler and the library are commonly separate (for
example, gcc uses whatever library is provided by the underlying
system). If the compiler is conforming and the library isn't, the
compiler *shouldn't* define __STDC_VERSION_ _ as 199901L, but it might
do so anyway.


[snip]

I don't agree with the statement that the "compiler and the library
are commonly separate". I don't know of a single other implementation
other than some gcc variants where this is so.

Do you know of any others?

--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://c-faq.com/
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.l earn.c-c++
http://www.contrib.andrew.cmu.edu/~a...FAQ-acllc.html
Jan 31 '06 #8
Jack Klein <ja*******@spam cop.net> writes:
On Mon, 30 Jan 2006 19:29:04 GMT, Keith Thompson <ks***@mib.or g> wrote
in comp.lang.c:
Eric Sosman <er*********@su n.com> writes: [...]
> `#if __STDC_VERSION_ _ >= 199901L' tests whether the
> implementation claims to conform to C99; if it does, the
> functions you're looking for are present.


It means that the compiler *claims* to conform to C99. If it's lying,
then it's not a conforming C compiler, and the requirements of the C
standard don't apply to it.

The compiler might not actually know whether the functions are
available. The compiler and the library are commonly separate (for
example, gcc uses whatever library is provided by the underlying
system). If the compiler is conforming and the library isn't, the
compiler *shouldn't* define __STDC_VERSION_ _ as 199901L, but it might
do so anyway.


[snip]

I don't agree with the statement that the "compiler and the library
are commonly separate". I don't know of a single other implementation
other than some gcc variants where this is so.

Do you know of any others?


Intel's icc is very similar to gcc. I suspect there are other
third-party compilers for Linux that use glibc as well.

But apart from those examples, I actually have very little idea how
common it is.

--
Keith Thompson (The_Other_Keit h) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Jan 31 '06 #9

"Jack Klein" <ja*******@spam cop.net> wrote in message
news:ak******** *************** *********@4ax.c om...
I don't agree with the statement that the "compiler and the library
are commonly separate". I don't know of a single other implementation
other than some gcc variants where this is so.

Do you know of any others?

--

Jack,

All HP C compiler implementations (HP-UX, Tru64 UNIX, and OpenVMS)
ship separately from the libraries. The libraries ship with the O.S. as
they
are needed by many applications that do not require the compilers.

Ed Vogel
HP C/C++ Engineering.


Jan 31 '06 #10

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

Similar topics

60
7308
by: Fotios | last post by:
Hi guys, I have put together a flexible client-side user agent detector (written in js). I thought that some of you may find it useful. Code is here: http://fotios.cc/software/ua_detect.htm The detector requires javascript 1.0 to work. This translates to netscape 2.0 and IE 3.0 (although maybe IE 2.0 also works with it)
6
4775
by: Gustav Medler | last post by:
Hello, there is a known problem with Opera and the execution of content shown in <NOSCRIPT> tag. Everythings works fine, if there is only one simple script like: http://www.dr-wald.de/test/Opera-NOSCRIPT.html Switching off Javascript will show the alternative content. Javascript enabled will only show the JS-content, _not_ the <NOSCRIPT> content.
0
1325
by: Gianni Mariani | last post by:
Below is an example of how to do static type-checking of an erroneous set of input masks. The drawback is that it's a little too verbose and non-trivial to understand and to make it truly I'd like to hear if you think this is overboard or you'd like to see more code like this ? ------------------------------------------------------------------------
8
4550
by: R. Smits | last post by:
I've have got this script, the only thing I want to be changed is the first part. It has to detect IE version 6 instead of just "Microsoft Internet Explorer". Can somebody help me out? I tried "Microsoft Internet Explorer 6" but that doesn't work. <SCRIPT LANGUAGE="Javascript"> <!-- bName = navigator.appName; if (bName =="Microsoft Internet Explorer") { document.write('<link media="screen" rel="STYLESHEET" type="text/css"
7
2657
by: mosaic | last post by:
Hi, all I really interested in how to check the memory leak of a program. Your smart guys, do you have excellent ideas that could share with me? Thank you. The following is my idea: In C programming language, there's a "malloc", there must a "free", my solution of the detection of leak is, find the corresponding "free" of "malloc". This the first condition.
0
1065
by: alexandru.nicau | last post by:
Hello All, I've got this huge class hierarchy (the naive solution to the following cannot be accepted). Throughout the code I need to instantiate a template wrapper class at several locations. Easy does, I change the code and wrap all the members I want into TmplWrp. Assume it's bad if I've got some member wrapped into TmplWrp then one of its descendants (think of class members - not of inheritance) also wrapped into TmplWrp. Can you...
0
1368
by: darrenhello | last post by:
hi there, I am doing my last year's project and I have a 'little' problem. I have to do an edge detection filter. for now, some normal edge detection filters that I used worked fine but there a problem. I need an edge detection filter in which I can offset the edge according to a variable that the user gives. The problem is that I got no idea of how to make an edge detection filter with an offset. anyone can help please? thank you
0
1926
by: origami.takarana | last post by:
Intrusion Detection Strategies ----------------------------------- Until now, we’ve primarily discussed monitoring in how it relates to intrusion detection, but there’s more to an overall intrusion detection installation than monitoring alone. Monitoring can help you spot problems in your network, as well as identify performance problems, but watching every second of traffic that passes through your network, manually searching for...
10
3263
by: Conrad Lender | last post by:
In a recent thread in this group, I said that in some cases object detection and feature tests weren't sufficient in the development of cross-browser applications, and that there were situations where you could improve the application by detecting the browser vendor/version. Some of the posters here disagreed. Since then, I've had to deal with a few of these cases; some of them could be rewritten to use object detection, and some couldn't....
0
9645
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9481
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
10155
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10095
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9953
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...
1
7502
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
5383
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5513
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4054
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

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.