Sunday, July 12, 2009

Is it possible to define new functions with the same names as standard library functions in 'C' language?

Yes. That's called "overloading."

Is it possible to define new functions with the same names as standard library functions in 'C' language?
Yes it is possible. However, the reason the library exists is to stnadardize many of the common elements required for writing code, so that people were not re-inventing the wheel each time they wrote a program in C.





That said, several string input functions--such as gets() and scanf()--are the source of many buffer overflow attacks by hackers. So it might be a good idea to re-write the headers, and use your own custom library of more secure functions. That way you will have more robust and secure code in your programs.
Reply:Sure. Just don't use the standard library header directly.
Reply:No, it is not possible.


Not if you link your program with standard library and use standard headers.





Overloading exists only in C++ and allows to define new functions with the same names, but different parameter types. Overloading does not apply to C language and standard C library functions.





You can't redefine, for example, function printf() or atoi(); If you make C function with the same name and parameter types, the program won't link because of naming conflicts.





In C++ program (but not C) you can make function with the same name as library function - like atoi() for example, but it has to have different parameter types, and it won't replace the original library function.


No comments:

Post a Comment