[comp.std.c] Error handling requirements of inlining code.

paulr@sequent.UUCP (Paul Reger) (08/26/89)

Have a question about inlining code.  Say a compiler is able to inline
code for optimzation reasons.  What error handling requirements are
imposed on the compiler when doing so ??

For example, say the code:

#include <math.h>
...
    double x;

    x = sqrt(-1.0);

...

is given the compiler, and it decides to inline sqrt().  Would the
standard require the compiler to also provide error handling of sqrt()
according to the standard library ???  (The standard library practice
for the error is to set errno to EDOM in this case, and return 0.0).

Or is this defined ??

Any help would be greatly appreciated.


Thank you,

             paulr       (Paul Reger)
     Sequent Computer Systems  Beaverton, OR.
 ... {sun,ucbvax!rutgers!ogccse,uunet}!sequent!paulr

henry@utzoo.uucp (Henry Spencer) (08/27/89)

In article <20708@sequent.UUCP> paulr@sequent.UUCP (Paul Reger) writes:
>Have a question about inlining code.  Say a compiler is able to inline
>code for optimzation reasons.  What error handling requirements are
>imposed on the compiler when doing so ??

It comes under the "as if" rule:  the behavior must be *the* *same* as
if inlining had not occurred -- insofar as ANSI C constrains the
behavior -- if you want to be standard-conforming.

Yes, this is a pain for error handling in math functions.
-- 
V7 /bin/mail source: 554 lines.|     Henry Spencer at U of Toronto Zoology
1989 X.400 specs: 2200+ pages. | uunet!attcan!utzoo!henry henry@zoo.toronto.edu

gwyn@smoke.BRL.MIL (Doug Gwyn) (08/28/89)

In article <20708@sequent.UUCP> paulr@sequent.UUCP (Paul Reger) writes:
-For example, say the code:
-#include <math.h>
-    double x;
-    x = sqrt(-1.0);
-is given the compiler, and it decides to inline sqrt().  Would the
-standard require the compiler to also provide error handling of sqrt()
-according to the standard library ???

The in-line code doesn't have to agree with the library, but it does
have to conform to the Standard.  On a domain error (as in your example),
EDOM must be stored in errno, and the function returns an implementation-
defined value (which may be a NaN, for example).  An exception must not
be raised.