In the current standard and probably the previous one (C11 and C99), the
absence of a prototype requires a diagnostic.
In the absence of a prototype, the compiler would not know the function is
variadic. It is my understanding that in the old days if a function had no
prototype, the compiler inferred/deduced the argument types from the first call
to the function and always assigned the function a return type of int.
Naturally, this would screw up functions such as sqrt. It would also severely
limit the utility of functions like fprintf. If you called it once with
fprintf(format_string_1, some_int);
and then later tried to call it with
fprintf(format_string_2, some_float);
the second call would result in the float being converted to int (to match the
implied prototype) which would not print correctly with a "%f" format. It
would even cause problems with a subsequent call of
fprintf(format_string_3, someother_int_1, someother_int_2);
because the compiler would now know that fprintf takes only two arguments.
> -----Original Message-----
> From: IBM Mainframe Discussion List [mailto:[email protected]] On
> Behalf Of Paul Gilmartin
> Sent: Tuesday, March 14, 2017 2:31 PM
> To: [email protected]
> Subject: Re: C fprintf() format code for 32-bit float?
>
> On Mon, 13 Mar 2017 21:50:30 -0700, retired mainframer wrote:
>
> >fprintf is a variadic function. Therefore any float passed to the function
> >will be automatically promoted to double before the function is called (as
> >long as the prototype is in scope). ...
> >
> Isn't that true even if the programmer provides no prototype? Necessarily,
> in order to preserve compatibility with code antedating the invention of
> function prototypes.
----------------------------------------------------------------------
For IBM-MAIN subscribe / signoff / archive access instructions,
send email to [email protected] with the message: INFO IBM-MAIN