On 11 Oct 2005 19:30:45 -0700, ""
<> wrote in comp.lang.c++:
> Hi, All:
>
> I defined another printf , same as printf function in libC.
> my question is why compiler choose my version of printf , not choose
> the printf in libC?
>
> Here is a piece of code:
>
> #include <stdio.h>
>
> int printf(char *str, ...)
> {
> return 1;
> }
>
> int main()
> {
> printf("hello world\n")
> }
>
> Rick
Defining a function with the same name and signature as a standard
library function in the global or std namespace is undefined behavior.
What your compiler does is whatever it wants to do, there is no right
or wrong result according to the C++ standard.
If you want to know why your compiler does what it does when you break
the rules, ask in a support group for your compiler. It is not a
language issue, C++ does not know or care what happens when you create
undefined behavior.
--
Jack Klein
Home:
http://JK-Technology.Com
FAQs for
comp.lang.c
http://www.eskimo.com/~scs/C-faq/top.html
comp.lang.c++
http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++
http://www.contrib.andrew.cmu.edu/~a...FAQ-acllc.html