Peter Nilsson <> writes:
> Keith Thompson <ks...@mib.org> wrote:
>> Acid Washed China Blue Jeans <chine.b...@yahoo.com> writes:
>> > Stanley Rice <hecong...@gmail.com> wrote:
>> > >
>> > > #include <stdio.h>
>> > > void my_print(float a, int b)
>> > > {
>> > > Â* Â* printf("%f\t%d\n", a, b);
>> > > }
>> > >
>> > > All three function are defined external without declaration in
>> > > file main.c. But why the first two works well, but the last one
>> > > fails? Is it undefined in ISO C?
>> >
>> > If you don't declare a function f, it is assumed to be
>> > Â* Â* Â* Â* int f()
>> > which passes all arguments with var-args rules.
>>
>> Not exactly, if by "var-args rules" you mean as if calling a variadic
>> function (one with ", ..." in its declaration).
>
> If they meant default argument promotions are applied to all
> arguments,
> then that _is_ how they're passed.
Yes and no. The default argument promotions are applied in the
same way; the calling convention may be quite different. That's why
calling a variadic function with no visible prototype has undefined
behavior, even in C90. (I still don't know what the previous poster
meant by "var-args rules".
>> Under C90 rules, the implicit declaration is for a function that
>> returns int with a fixed number of parameters corresponding to the
>> promoted types of the actual arguments in the call.
>
> No, the implicit declaration is simply int f(), i.e. a function
> returning int with an unspecified number of parameters.
You're right, thanks for the correction.
C90 6.3.2.2 says:
If the expression that precedes the parenthesized argument list
in a function call consists solely of an identifier, and if
no declaration is visible for this identifier, the identifier
is implicitly declared exactly as if, in the innermost block
containing the function call, the declaration
extern int identifier () ;
appeared.
(The effect of the nonexistent rule that I described would be similar to
the actual rule in the case of a single call.)
[snip]
--
Keith Thompson (The_Other_Keith)
kst- <http://www.ghoti.net/~kst>
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"