Possible Duplicate:
Does C support overloading ?
I would like to know if printf supports function overloading in C, since same printf function may be used in more than one way in one C program.
Possible Duplicate:
Does C support overloading ?
I would like to know if printf supports function overloading in C, since same printf function may be used in more than one way in one C program.
If you mean the difference between
printf("something: %d\n", number);
printf("something else: %d, %s\n", number, string);
this has nothing to do with overloading. It's just a variadic function
printf()
in C is a variadic function which can be thought of as a form of overloading. Unlike overloaded functions in languages like C++, Java, C# etc., a variadic function is not type-safe which is why they are somewhat frowned upon.
If you're asking how printf
takes different numbers and types of arguements, then no, it isn't function overloading. Functions can be defined to take variable argument lists.
Look at stdarg.h for working with variable arguement lists
C doesn't have signature based polymorphism so you can't do this. There are a few ways you can sort of do this listed here.
The more important question is why you would want to do this? Why is printf not generic enough for you?