Method overloading in C with printf? [duplicate]
Possible Duplicate:
What is the signature of printf? Does C support overloading? Does prin开发者_如何学JAVAtf support function overloading In C?
C's printf
function seems to show method overloading as different types of arguments can be given to it. Is this right or printf
is something else?
printf()
is something else that is called variadic function. The exact number and types of its arguments is specified through its first one, the format.
Other variadic functions have other ways of specifying number and/or type of arguments but it is always through one fixed argument.
It's not method overloading at all. Method overloading respects types. printf
just flat out ignores them and hopes you got it right in the format specifier.
printf
is a variadic function, so it determines at run-time how many arguments to expect based on the format specifier you give it.
Whether that counts as "overloading" depends on your definition! Most people would say it isn't, because it's nothing to do with the compiler (only one function is instantiated in binary). But from the user's perspective, it still acts a lot like overloading (just not type-safe).
精彩评论