Sujet : Re: question about linker
De : tr.17687 (at) *nospam* z991.linuxsc.com (Tim Rentsch)
Groupes : comp.lang.cDate : 28. Nov 2024, 00:18:33
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <868qt4qn92.fsf@linuxsc.com>
References : 1 2 3 4 5 6 7
User-Agent : Gnus/5.11 (Gnus v5.11) Emacs/22.4 (gnu/linux)
Michael S <
already5chosen@yahoo.com> writes:
On Wed, 27 Nov 2024 08:08:34 -0300
Thiago Adams <thiago.adams@gmail.com> wrote:
>
Without function prototypes, the compiler will use the types it
has on the caller's side, possibly with integer promotions.
>
Calling a function with a double will assume the function is
implemented receiving a double.
The function implementation will need to match these types.
>
With function prototypes, we can call a f(int i) with f(1.1) and
then the caller side will convert before calling f.
>
Yes. With one more complication that there was floating-point
promotion as well as integer promotion. IIRC, before they
invented prototypes it was impossible to write functions with
'float' parameters.
I believe the last statement there isn't exactly right. If we
have a K&R-style function definition, as for example
int
not_too_small( f )
float f;
{
return f > 1.e-250;
}
that declares a parameter 'f' with type float, then as far as the
body of the function is concerned the type of 'f' is float. It is
of course true that, as far as callers are concerned, the function
expects a double argument, but that isn't the same as a double
parameter. Consider this similar function:
int
not_too_small_two( f )
double f;
{
return f > 1.e-250;
}
These two function do not have the same behavior. The reason for
that difference is that in one case any argument value is left as
is (as a double), and is treated as such, and in the other case
any argument value is converted (inside the function body) from a
double to a float, and is treated within the function body as a
float object, not as a double object. (Calling with 1.e-200 as
an argument should show one case of different behaviors.)