Re: make compilation fail



CBFalconer wrote:
> Malcolm wrote:
> > ...
> > It's the other way round. In the olden days, it was sometimes
> > the done thing to call functions without a prototype. It is still
> > possible to do this in some cases for reasons of backwards
> > compatibility, but things have tightened up. Current thinking is
> > that prototypes are desireable and compilers should complain if
> > not given them. Certainly you should always include stdio.h if
> > you
> > wnat to use printf().
>
> Not only should, but must. Using any variadic function without a
> prototype in scope results in undefined behaviour.

You don't _have_ to include <stdio.h> to get a prototype for
printf...

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

int main(void)
{
printf("%s %s\n", "Hello", "World");
return 0;
}

This is valid in C99 too, even though the first parameter of
printf is normally restrict qualified.

--
Peter

.



Relevant Pages

  • Re: Can u tell me the explanation reg this problem
    ... value although it's implicitly declared to return int and there isn't a ... proper prototype of printf in scope), ... the Rationale addresses exactly the case at hand: ...
    (comp.lang.c)
  • Re: How does the compiler do with this code?
    ... It then assumes printf takes the amount of argumnets you call ... of type int, ... That's the _actual_ prototype. ... with a single argument of type char *, ...
    (comp.os.linux.development.apps)
  • Re: Question regarding prototypes for 0-ary functions.
    ... returning an int. ... The paragraph I quoted says "... ... If the function is defined with a type that includes a prototype, ... "int printf()" is not a prototype; therefore if that declaration is in scope at the point where the call to printfoccurs, the first condition specified above has been met. ...
    (comp.lang.c)
  • Re: How does the compiler do with this code?
    ... It then assumes printf takes the amount of argumnets you call ... of type int, ... IIRC the compiler assumes that the *supplied* arguments are ... That's the _actual_ prototype. ...
    (comp.os.linux.development.apps)
  • Re: Urgent C Questions
    ... int, not void. ... Then you need to turn up the warning level on QuickC. ... 3  missing prototype for 'main' ... stdio.h contains the declaration for printf: ...
    (comp.lang.c)