473,796 Members | 2,434 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
11 2784


Ed Vogel wrote On 01/31/06 09:06,:
"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.


That's usually the case, but distribution and
integration are different things. The macros defined
by the compiler and headers must correctly describe
the library and the operating environment, or else
"the implementation" is non-conforming. The Standard
has no notion (in hosted systems) of separating the
compiler from the library, just as it has no notion
of separating the preprocessor from the rest of the
compiler. Real systems are often built from modules,
but the Standard speaks only of the integrated whole.

... which isn't to say that the compilers and
libraries are always properly integrated. As Ken
Thompson pointed out, a compiler that defines
__STDC_VERSION_ _ as 199901L might find itself deployed
with a library that doesn't conform to C99. That's a
bit like deploying tires of different sizes on the
left and right sides of your car; none of the tires
is "wrong" in and of itself, but the combination of
mismatched sizes is invalid anyhow.

From the programmer's perspective, I think you must
trust __STDC_VERSION_ _, just as you trust longjmp().
A C99 compiler mis-deployed with a C89 library will
deceive you; equally, a compiler that uses one flavor of
compiler magic in its setjmp() will produce code that
is likely to fail if deployed with a library whose
longjmp() expects a different sort of magic. Sometimes
it will turn out that your trust is misplaced; that's
the way things are in an imperfect world. But what's
the alternative? Run a complete conformance test suite
before starting each compilation? Trust the compiler,
I say, and realize that it may lie very occasionally.

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

Jan 31 '06 #11
Eric Sosman <er*********@su n.com> writes:
[...]
... which isn't to say that the compilers and
libraries are always properly integrated. As Ken
Thompson pointed out, a compiler that defines
__STDC_VERSION_ _ as 199901L might find itself deployed
with a library that doesn't conform to C99. That's a
bit like deploying tires of different sizes on the
left and right sides of your car; none of the tires
is "wrong" in and of itself, but the combination of
mismatched sizes is invalid anyhow.
I think you meant Keith Thompson, not Ken Thompson.
From the programmer's perspective, I think you must
trust __STDC_VERSION_ _, just as you trust longjmp().
A C99 compiler mis-deployed with a C89 library will
deceive you; equally, a compiler that uses one flavor of
compiler magic in its setjmp() will produce code that
is likely to fail if deployed with a library whose
longjmp() expects a different sort of magic. Sometimes
it will turn out that your trust is misplaced; that's
the way things are in an imperfect world. But what's
the alternative? Run a complete conformance test suite
before starting each compilation? Trust the compiler,
I say, and realize that it may lie very occasionally.


My concern is that this kind of compiler vs. library mismatch may be
quite common. gcc is one of the most widely used C compilers, and it
uses whatever C library happens to exist on the system where it's
installed.

I remember having a similar problem many years ago under SunOS 4.1.3.
The system-provided sprintf() function, if I recall correctly,
returned a char* rather than an int (this was a pre-ANSI
implementation) , but gcc claimed to be C90-conforming (as the compiler
itself was, as far as I know). Ideally the gcc installation procedure
should have detected this and adjusted __STDC__ appropriately, but I
don't think it did.

If this is a common kind of bug, it's probably worth testing for, at
least for specific known cases of it.

--
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.
Feb 1 '06 #12

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

Similar topics

60
7310
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
1369
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
1929
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
3265
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
9680
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
9528
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
10455
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
10006
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
9052
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...
0
6788
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
5573
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4116
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
3731
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.