Sanjeev Gopinath <sanjeevsinc...@...> wrote:
> printf and scanf have been declared in stdio.h.
> But why are we allowed to use them even without including
> stdio.h?

For the same reason you're 'allowed' to stick a fork in a toaster
without reading the warning labels. ;)

Variadic functions (those without a fixed number of parameters)
must be prototyped prior to use.[1] It is (IMO) a language defect
that prototypes are not required for all functions, but C is
not a language for the faint hearted.[2]

You can use printf without including <stdio.h>, but only if you
provide an equivalent prototype, e.g. ...

  int printf(const char *, ...);

...somewhere prior to calling it.

[1] C90 compilers however are not required to issue a diagnostic
(warning or error) if you fail to do so.

[2] C99 stops short of requiring prototypes, but it does
require a declaration for named functions. It's not possible
to properly declare printf without supplying a full prototype.

-- 
Peter

Reply via email to