Re: function prototype vs function declaration



Ravishankar S wrote:


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

<snip>

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.

I think you should stop writing tutorials and start reading them.
There is a very important distinction between a declaration and a
prototype, and you do your readers a disservice by not making the
distinction clear.

I am making that distinction.Its only the perception that differs. I
was infact wondering whether I should make that
sentence ("there is a minor yet important difference between function
declaration and function prototype"). But I changed
since I have to make its importance clear.

I am sure 90/100 C progrmmers are not aware of this distiction given
now that function
prototypes are common.

However it is better to accurately explain the language as it is
formalised rather than as it might be commonly used. Flushing stdin,
voiding main and using gets seem to be distressingly common in real
world usage, but a tutorial that uses them other than to describe their
dangers, would be considered of very low quality.

What's more, there are (rather recondite) circumstances where you
could conceivably need to eschew the prototype form - I'm thinking
particularly of arrays of pointer to function where not all the
functions have the same type. It is important to know when to use the
prototype form (i.e. nearly always) and when it *might* be a good
idea not to.

I was thinking that my conclusions are fairly accurate!
But I cannot help but note that what you have mentioned may also be
achieved by using void pointer's.

No. void pointers are quite different from function pointers. Please
read a good textbook before continuing on your tutorial.

.



Relevant Pages

  • compiling ibcs on Debian 3.0 / 2.4.19 kernel and on Debian 2.2r5 / 2.2.26 kernel
    ... warning: this is the location of the previous ... declaration isn't a prototype ... incompatible pointer type ...
    (Debian-User)
  • Re: [SLE] compile problem -- WebCam
    ... > the archive and issue the make command. ... > declaration isn't a prototype ... > definition has no type or storage class ...
    (SuSE)
  • Re: General question
    ... declaration for, it assumed that it was a function returning an int ... The first true C standard, ANSI/ISO of 1989 and 1990, changed things. ... Its prototype is: ...
    (comp.lang.c)
  • Re: (part 21) Han from China answers your C questions
    ... not supplying a prototype for main. ... of a definition of that function specifies that no information about ... declared function has no parameters means this declaration does ... Syntactically, it does in fact match the K&R-style syntax rule, ...
    (comp.lang.c)
  • Re: Some Questions #2
    ... "if expr1 and expr2 are expressions, ... a byte is defined as synonymous with a char. ... A declaration describes the type of object or function ... A prototype is a description of a function's parameters. ...
    (comp.lang.c)