Go Back   Rhinocerus > Newsgroup > Newsgroup comp.lang.c

Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old 08-07-2012, 06:01 AM
Hill Pang
Guest
 
Posts: n/a
Default What's the difference between function declaration and function prototype?

I can find some answer from web, but I can't find their definitions in the C99 standard so far.

Which page is it in?

Thanks in advance.
Reply With Quote
Alt Today
Advertising
 
and become member of Rhinocerus
Standard Sponsored Links

  #2 (permalink)  
Old 08-07-2012, 06:16 AM
Keith Thompson
Guest
 
Posts: n/a
Default Re: What's the difference between function declaration and function prototype?

Hill Pang <pangbw@gmail.com> writes:
> I can find some answer from web, but I can't find their definitions in
> the C99 standard so far.
>
> Which page is it in?


A function prototype is a *kind* of function declaration, one that
specifies the types of the parameters. A non-prototype declaration
has empty parentheses; it's also known as an old-style or K&R-style
declaration, and it's obsolescent.

The term "prototype" is defined in C99 and C11 6.2.1p2:

A *function prototype* is a declaration of a function that declares
the types of its parameters.

--
Keith Thompson (The_Other_Keith) kst-u@mib.org <http://www.ghoti.net/~kst>
Will write code for food.
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Reply With Quote
  #3 (permalink)  
Old 08-07-2012, 05:30 PM
Varun Tewari
Guest
 
Posts: n/a
Default Re: What's the difference between function declaration and function prototype?

There a little difference, but in modern context, they are same.
Reply With Quote
  #4 (permalink)  
Old 08-07-2012, 05:55 PM
Eric Sosman
Guest
 
Posts: n/a
Default Re: What's the difference between function declaration and functionprototype?

On 8/7/2012 1:30 PM, Varun Tewari wrote:
> There a little difference, but in modern context, they are same.


That seems misleading. Keith Thompson quoted the actual
definition: "A function prototype is a declaration of a function
that declares the types of its parameters." The very definition
suggests the existence of function declarations that omit the
parameter types, and indeed if you look elsewhere in the Standard
you will find the rules for declaring functions this way.

By "in modern context," I imagine you mean something like
"always use prototypes, because a compiler that can't handle them
cannot possibly be `modern'." That's good advice: There is almost
never a reason to omit the parameter types, and I'd venture that
even when a reason exists it's probably a weak one. The Standard
describes non-prototype function declarations as an "obsolecent
feature" of the language, and even if it never gets all the way to
"obsolete" the message is clear: Don't Do That.

Still, when language feature F comes in forms F1 and F2, with
F1 discouraged and F2 strongly recommended, I think someone who
asks "What's the difference between F and F2" deserves more of an
answer than "Never mind."

--
Eric Sosman
esosman@ieee-dot-org.invalid
Reply With Quote
  #5 (permalink)  
Old 08-16-2012, 09:37 AM
karora129@gmail.com
Guest
 
Posts: n/a
Default Re: What's the difference between function declaration and function prototype?

prototype and declaration both are same
Reply With Quote
  #6 (permalink)  
Old 08-16-2012, 11:48 AM
James Kuyper
Guest
 
Posts: n/a
Default Re: What's the difference between function declaration and functionprototype?

On 08/16/2012 05:37 AM, karora129@gmail.com wrote:
> prototype and declaration both are same


Are you claiming that "int func();" is a function prototype? Or are you
claiming that it's not a function declaration?
--
James Kuyper
Reply With Quote
  #7 (permalink)  
Old 08-16-2012, 12:18 PM
Nick Keighley
Guest
 
Posts: n/a
Default Re: What's the difference between function declaration and function prototype?

On Aug 7, 6:55*pm, Eric Sosman <esos...@ieee-dot-org.invalid> wrote:
> On 8/7/2012 1:30 PM, Varun Tewari wrote:


> > There a little difference, but in modern context, they are same.


<snip>

> * * *By "in modern context," I imagine you mean something like
> "always use prototypes, because a compiler that can't handle them
> cannot possibly be `modern'." *That's good advice: There is almost
> never a reason to omit the parameter types, and I'd venture that
> even when a reason exists it's probably a weak one.


maintaining K&R style code. Yes it's still about. It's only a couple
of years since I modified a K&R program.

> *The Standard
> describes non-prototype function declarations as an "obsolecent
> feature" of the language, and even if it never gets all the way to
> "obsolete" the message is clear: Don't Do That.


<snip>
Reply With Quote
  #8 (permalink)  
Old 08-16-2012, 03:07 PM
Kenneth Brody
Guest
 
Posts: n/a
Default Re: What's the difference between function declaration and functionprototype?

On 8/16/2012 8:18 AM, Nick Keighley wrote:
> On Aug 7, 6:55 pm, Eric Sosman <esos...@ieee-dot-org.invalid> wrote:
>> On 8/7/2012 1:30 PM, Varun Tewari wrote:

>
>>> There a little difference, but in modern context, they are same.

>
> <snip>
>
>> By "in modern context," I imagine you mean something like
>> "always use prototypes, because a compiler that can't handle them
>> cannot possibly be `modern'." That's good advice: There is almost
>> never a reason to omit the parameter types, and I'd venture that
>> even when a reason exists it's probably a weak one.

>
> maintaining K&R style code. Yes it's still about. It's only a couple
> of years since I modified a K&R program.

[...]

Until recently, the code I maintain had to be able to compile on HP-UX. The
C compiler that came with the system would recognize prototypes, and tell
you that you needed to buy their other C compiler if you needed prototype
support.

As I recall, there is now a gcc for HP-UX, eliminating that hurdle.

--
Kenneth Brody
Reply With Quote
 
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off




All times are GMT. The time now is 05:49 PM.


Copyright ©2009

LinkBacks Enabled by vBSEO 3.3.0 RC2 © 2009, Crawlability, Inc.