Reputation: 7396
I always asked my self this question, Why printf() in C was designed to accept any number of parameters, isn't that Overloading? if yes how does a pure structured language contains an Object oriented language concept like Method overloading?
Upvotes: 3
Views: 178
Reputation: 393719
This is called varargs (variadic number of arguments) and existed since the early days of C.
This has no relation with overloading.
In a sense, it is just 'an open prototype', expressing the fact that prototypes weren't always as strictly used as nowadays. The flexibility of C in this department stems from the way in which parameters are passed: the cleanup of parameters is the responsibility of the caller, which can know how much room they occupied at the required times.
Similar techniques would not have been possible (easy) with competing calling conventions (e.g. Pascal calling convention)
Upvotes: 2
Reputation: 10995
It isn't overloading.. any method that takes a variable number of argument is called a variadic function.
Variadic methods on wiki
Upvotes: 2
Reputation: 726987
isn't that Overloading?
No, there is no overloading in C. It is called a "variadic function".
And no, despite its appearance in C++ and absence from C, method overloading is not an object-oriented concept. It is featured prominently in rather old programming languages, such as Prolog, that are not object-oriented.
Upvotes: 7