On Sun, Feb 7, 2010 at 5:05 PM, SUBODH ROHILLA <[email protected]>wrote:

> I have tried compling it with g++ and also with g++ -Wall , but it gives no
> error warning message. It runs smoothly
>
> On Sun, Feb 7, 2010 at 4:51 PM, Prashant Batra <[email protected]
> >wrote:
>
> > On Sat, Feb 6, 2010 at 4:29 PM, rakesh kumar <[email protected]>
> wrote:
> > > Hi all,
> > >         Today while studying a book i just saw the following lines of
> > code:
> > > int main(void)
> > > {
> > >  int printf(const char *n,...);
> > The local declaration(prototype of the function)
> > >  int a=1;
> > >  printf("abcdef");
> > Calls the C library printf() function.at the time of linking.
> > > return 0;
> > > }c
> > >
> > >  and the output was: abcdef
> > > When i tried to run this code, it ran well without any error and this
> was
> > > asked in GATE exam also. I am confused, how it ran without <stdio.h>,
> > when i
> > > used printf() function and gave the same output as printf gives. Okay
> > after
> > > that i commented the third line "int printf(const char *n,....);", the
> > > output didn't get affected. Now i am thinking when we can use printf()
> > > function without any prototype or defining any header, then why do we
> > need
> > > to use #include<> in our program, because when i changed this program a
> > bit
> > > by substituting printf() with scanf() it worked fine like scanf() does
> > > normally.
> > >  Can anyone explain me,what is this?
> > The C compiler is a bit lenient in syntactic analysis part for
> > functions. It assumes a default declaration. And while linking links
> > your printf() call to the library fucntion.But it should give
> > warning(saying some implicit declaration).
> > just try compiling with -Wall option set, you will get the warning.
> > Also compile the code using g++, it will give error, saying prototype not
> > found.
> > > Thanks
>

No. It won't generate any warnings as -lc (link with C library flag) is
implicit in gcc ver 3.3+ (gcc now has its own builtin libc). IIRC,
-fno-builtin should generate an error.

> > _______________________________________________
> > > Ilugd mailing list
> > > [email protected]
> > > http://frodo.hserus.net/mailman/listinfo/ilugd
> > >
> >
> > _______________________________________________
> > Ilugd mailing list
> > [email protected]
> > http://frodo.hserus.net/mailman/listinfo/ilugd
> >
> _______________________________________________
> Ilugd mailing list
> [email protected]
> http://frodo.hserus.net/mailman/listinfo/ilugd
>



-- 
-- 
Ankit Chaturvedi
GPG: 05DE FDC5 468B 7D9F 9F45 72F1 F7B9 9E16 ECA2 CC23
<http://www.google.com/profiles/ankit.chaturvedi>
_______________________________________________
Ilugd mailing list
[email protected]
http://frodo.hserus.net/mailman/listinfo/ilugd

Reply via email to