Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
| From | Keith Thompson <kst-u@mib.org> |
|---|---|
| Newsgroups | comp.lang.c |
| Subject | Re: C function prototype and body definitions |
| Date | 2015-10-23 12:19 -0700 |
| Organization | None to speak of |
| Message-ID | <ln4mhhwfyz.fsf@kst-u.example.com> (permalink) |
| References | <ae13b44e-6dd4-4ff6-b62c-c0c8c58fbe50@googlegroups.com> <01da979a-4815-4092-9c2f-e9df44643113@googlegroups.com> |
Malcolm McLean <malcolm.mclean5@btinternet.com> writes:
> On Friday, October 23, 2015 at 6:37:25 PM UTC+1, Rick C. Hodgin wrote:
>> What is the reason for having both a function prototype and a body
>> definition, when the body typically replicates the prototype?
>>
> For historical reasons. Prototypes were added at a fairly
> late stage in the development of C, whilst argument lists have
> been in from the beginning, although they were specified
> after the function name rather than in the parentheses.
>
> However it also means the the programmer has a list of the
> parameters when he's working on the function body, without
> having to flip back to the prototype. If you were redesigning
> C from scratch, you'd get rid of the prototypes and have some
> mechanism for export, rather than keep the prototypes and
> get rid of the parameter list at the head of the body.
Maybe you would. Personally I think there are considerable advantages
in separating the interface and implementation into separate source
files (e.g., foo.h and foo.c), while having each function definition
repeat the information given by the declaration (with the compiler
checking that it's consistent). In my experience it isn't difficult to
maintain.
An alternative would be to put everything in a single source file and
perhaps have some extra tool that generates an interface, showing just
the declarations that are "exported" to clients.
--
Keith Thompson (The_Other_Keith) kst-u@mib.org <http://www.ghoti.net/~kst>
Working, but not speaking, for JetHead Development, Inc.
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
C function prototype and body definitions "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2015-10-23 10:37 -0700
Re: C function prototype and body definitions Melzzzzz <mel@zzzzz.com> - 2015-10-23 19:44 +0200
Re: C function prototype and body definitions Malcolm McLean <malcolm.mclean5@btinternet.com> - 2015-10-23 10:53 -0700
Re: C function prototype and body definitions Keith Thompson <kst-u@mib.org> - 2015-10-23 12:19 -0700
Re: C function prototype and body definitions "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2015-10-23 12:27 -0700
Re: C function prototype and body definitions supercat@casperkitty.com - 2015-10-24 10:46 -0700
Re: C function prototype and body definitions "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2015-10-24 12:17 -0700
Re: C function prototype and body definitions Les Cargill <lcargill99@comcast.com> - 2015-10-23 20:56 -0500
Re: C function prototype and body definitions gazelle@shell.xmission.com (Kenny McCormack) - 2015-10-24 09:49 +0000
Re: C function prototype and body definitions Bartc <bc@freeuk.com> - 2015-10-23 19:16 +0100
Re: C function prototype and body definitions Barry Schwarz <schwarzb@dqel.com> - 2015-10-23 11:30 -0700
Re: C function prototype and body definitions sfisher@panix.com (Stephen Fisher) - 2015-10-23 15:58 -0600
Re: C function prototype and body definitions Les Cargill <lcargill99@comcast.com> - 2015-10-23 20:54 -0500
csiph-web