No generic intrinsic functions in ANSI-C
David Hough
sun!Eng!David.Hough
Mon May 13 19:21:35 PDT 1991
> >So in the following,
> >assume a hosted environment and no local static definitions.
> >
> > printf(" xyz ...", p1, p2, p3, ...) MUST be recognized by the compiler
> > and the right thing done (for instance checking correspondence of
> > parameters to formats) whether or not a prototype is in scope,
> > even in the case where the varargs calling sequence is different
> > from the normal one.
> >
> >True, because printf is a defined standard library function.
>
> False. A compiler is not required to recognize any name as special, even in
> a hosted implementation.
Section 4.1.6 says "Provided that a function type can be declared without
reference to any type defined in a header, it is also permissible to
declare the function, either explicitly or implicitly, and use it without
including its associated header. If a function that accepts a variable number
of arguments is not declared (explicitly or by including its associated
header), the behavior is not defined." I think the "implicitly" may have
misled me: one might suppose that using exp() without an
explicit definition would lead to the correct thing happening (the thing one
intended to imply) but the standard defines implicit function definition
very explicitly in 3.3.2.2 as extern int. And in any event 4.1.6
says implementations aren't required to do anything about varargs functions,
even printf, so portable code can't rely on any particular behavior.
What I should have said (as I did in my first posting) is that a compiler MAY
recognize printf... if it's a hosted implementation.
> With respect to whether <math.h> functions can vary their precision based on
> a call's argument types, I believe that the intent is to allow such and that
> the standard does not preclude it. (The only real question is in regards
> errno's setting.)
How about extending e.g. abs, sqrt, and exp to various integer and floating
types, including nonstandard extensions like long long, long float,
complex, or interval? What does the ANSI-C standard require/permit/forbid?
And if NCEG implementations are allowed to ignore the ANSI-C errno requirements,
how much more harm does it do to require NCEG implementations
to interpret the math.h functions as generic
intrinsic operators whenever no other interpretation is specified in
the user code? (e.g. when "exp" is used with no definition in scope
or with no definition except #include <math.h>).
More information about the Numeric-interest
mailing list