Re: function prototype vs function declaration



Ravishankar S wrote:

"santosh" <santosh.k83@xxxxxxxxx> wrote in message
news:fk89fa$tmr$1@xxxxxxxxxxxxxxxxxxxxxxxxxxxx
Ravishankar S wrote:


"Richard Heathfield" <rjh@xxxxxxxxxxxxxxx> wrote in message
news:eNWdnUUdru5UPvranZ2dnUVZ8qXinZ2d@xxxxxxxxx
Ravishankar S said:

<snip>

It turns out that function
declarations and function prototypes are the same thing in
standard C.

No, it doesn't.

It is true that all function prototypes are function declarations,
but it is not true that all function declarations are function
prototypes.

<snip>

an example would help here.

int fx();

This is a function declaration, but not a prototype. In fact,
argument checking is turned of for functions declared like this. This
is for backwards compatibility and not recommended for new code. Use:

int fx(void);

or specify the parameters explicitly, as a prototype.

Thanks.

My amended article would be:

It turns out that there is no difference between function declarations
and function prototypes as far as modern use of C is concerned.

No. With well written programs there prototypes may serve as
declarations, but this is by no means guaranteed. Saying "no
difference..." is too simplistic.

<snip>

ANSI C mandates function prototypes as the method for function
declaration.

Recommends, but not mandates.

.



Relevant Pages

  • Re: Is this acceptable (i.e., compliant) code?
    ... I also only have them place those prototypes ... But he didn't say to put them in a header; ... topdown, I put *all* forward declarations before main, or the other ... > prototypes are an error source. ...
    (comp.lang.c)
  • Re: function prototype vs function declaration
    ... It is true that all function prototypes are function declarations, ... The C standard explicitly allows the use ...
    (comp.lang.c)
  • Re: function prototype vs function declaration
    ... It turns out that there is no difference between function declarations ... function prototypes as far as modern use of C is concerned. ... University of Colorado, Colorado Springs ... Text books do not trump the standard, and the standard explicitly allows functions declarations that are *not* prototypes. ...
    (comp.lang.c)
  • Re: function prototype vs function declaration
    ... It is true that all function prototypes are function declarations, ... int fx; ...
    (comp.lang.c)
  • Re: Function prototypes
    ... that has any output, without using prototypes. ... and thereby getting prototype declarations). ... It's certainly more convenient to have *printf, ...
    (comp.lang.c)