more on ANSI-C <math.h> functions

David Hough sun!Eng!David.Hough
Tue May 14 15:16:35 PDT 1991


The current "Floating-Point C Extensions" document, NCEG 91-015,
says (page 21)

"ANSI C allows most library functions to be implemented as both macros
and functions.  The macro and function versions may differ in certain
ways.  In particular, the macro versions have license to keep arguments
in wider representations than their declared types - similar to the
explicit license for wide expression evaluation. (ANSI 3.2.1.5)"

The conclusion I'd draw from the recent discussion is that whether or
not a library function is defined as a macro has no effect on whether
arguments may be widened.  A library function may be implemented inline
whether or not there is a corresponding macro definition in the include
file; the constraint is only that #undef sqrt or (sqrt) will positively
cause a function called sqrt to be invoked.  In the absence of #undef sqrt,
a program written like

#ifdef sqrt
	y=sqrt(x);
#else
	y=sqrt(x);
#endif

may neither assume that identical code will be generated in both cases nor
that different code will be generated.

Right or wrong?



More information about the Numeric-interest mailing list