how does printf work internally inside C? it is evident that printf funtions can have any number of arguments. does c support function overloading?? if yes how
how does printf work internally inside C? it is evident that printf funtions can have any number of arguments. does c support function overloading?? if yes how
no, it does not support function overloading. It puts all of the values at the end of the argument list into one list.
Last edited by Polymorphic OOP; 12-12-2002 at 10:06 PM.
any idea on how it does that? coz i am trying to implement my own printf function.
Thnx a lot...!! It really helped
Do you guys think it's a blessing or not that C does not support function overloading? Sometimes I find that it could make things alot easier, but then I also think it's good, in some cases, to make a function that says in it's name what types are in use, like addIntToList, and addStringToList, etc etc.
What are your thoughts?
doesn't dmalloc overload the malloc and free functions in c?
i think by placing the header file at the end of the includes as a specified library. just like local variables take precidence over global variables of the same name.
No, function overloading doesn't exist in Cdoesn't dmalloc overload the malloc and free functions in c?
I wasn't asking if it has been done before or not, I was asking if thought it was good that it is not in C or not.> What are your thoughts?
I think this has already been done, and the result is C++
>Do you guys think it's a blessing or not that C does not support
>function overloading?
I don't think it is a blessing. One of the problems with not being able to have things like function overloading is that you'll have a lot of functions like the ones you already mentioned, addIntToList and addStringToList, functions which do almost the same, but only the types on which they work are different. Such namespace pollution could be avoided by function overloading.
Or, you could make use of void-pointers. I recently saw an implementation by someone using this struct:
He used it to implement many datastructures, like trees, graphs and lists.Code:struct node { void *node1; void *node2; void *node3; };
Another implementation I have seen some time ago was by using typedef. The programmer used defines in his code and if other types were needed in some function, he changed the define.
Like:
Code:#define my_type int my_type *add_to_list (my_type var)
With function overloading you still have to write all the functions though, you just have them all the same name.
not nessecarily; templating comes in there.
hello, internet!
>>With function overloading you still have to write all the functions though, you just have them all the same name.
by this definition, dmalloc overloads the malloc and free functions in c
Last edited by rotis23; 12-13-2002 at 05:30 PM.
no, it doesn't. There is no function overloading in C. Post up a quick example of dmalloc and explain why you think it's overloading. If it has a different function name, then you aren't overloading it.
ok, by ortbitz previous definition
consider the code:
installing dmalloc and inserting the line below other includes:Code:#include <stdio.h> #include <stdlib.h> int main() { char *test; test = malloc(sizeof(char) * 15) strcpy(test,"this is a test"); printf("test : %s\n"); free(test); }
the dmalloc library's own dmalloc and free functions are called instead of those in the stdlib.h library.Code:#include "dmalloc.h"
2 things -- first that wouldn't be overloading even if it were true because overloading is when you have 2 different versions of the function that take different arguments
So right off the bat, it's not overloading.
As for what IS happening, here's the most likely possibility
They simply just defined their own versions of the function. There's nothing wrong with that. If that is what they did, then try this:
#include BOTH stdlib.h and dmalloc.h If you get an error saying that malloc and free were defined twice, then all they did was provide theiur own definitions of the function.