Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
| From | Stephen Sprunk <stephen@sprunk.org> |
|---|---|
| Newsgroups | comp.lang.c |
| Subject | Re: Function Prototypes: Necessary or just good practice? |
| Date | 2012-02-14 01:18 -0600 |
| Organization | A noiseless patient Spider |
| Message-ID | <jhd1si$sbf$1@dont-email.me> (permalink) |
| References | <jhcq3f$sch$1@news.albasani.net> |
On 13-Feb-12 23:05, /dev/phaeton wrote:
> In K&R2, function definitions in a program were preceded by a function
> prototype, i.e.:
>
> int my_function(int variable1, int variable2);
Note this is a prototyped function _declaration_.
> Then somewhere down the line is the actual definition of the function
> itself:
>
> int my_function(int variable1, int variable2)
> {
> do;
> some;
> stuff;
> return (some_value);
> }
This is a prototyped function _definition_. Note that a definition
declares the function as well, if that hasn't already been done.
> However, I've noticed that if I omit the function prototype,
ITYM the function declaration.
> the program compiles (with gcc 4.6.x at least) and runs just fine.
Since you don't include the rest of the program's source, we don't know
if this is luck or you just didn't happen to do something wrong.
Lots of stuff happens to work "just fine" on some implementations even
though that may not be guaranteed.
> Is this something that's now acceptable in ANSI standards since K&R2
> was printed? Or is this 'compiler forgiveness'- letting me do something I
> probably shouldn't?
It's not new; in fact, it's the old (pre-ANSI) way of doing things.
K&R C allowed calling functions that hadn't previously been declared,
which caused an implicit declaration of a function by that name. This
was deprecated by ANSI. Unless you _know_ you are coding for a platform
for which there is no C89 (or later) compiler, which should be
incredibly rare these days, you should always declare your functions.
S
--
Stephen Sprunk "God does not play dice." --Albert Einstein
CCIE #3723 "God is an inveterate gambler, and He throws the
K5SSS dice at every possible opportunity." --Stephen Hawking
Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Function Prototypes: Necessary or just good practice? /dev/phaeton <blahbleh666@no_more_spam.hotmail.com> - 2012-02-13 23:05 -0600
Re: Function Prototypes: Necessary or just good practice? Johann Klammer <klammerj@NOSPAM.a1.net> - 2012-02-14 07:31 +0100
Re: Function Prototypes: Necessary or just good practice? Ben Bacarisse <ben.usenet@bsb.me.uk> - 2012-02-14 13:14 +0000
Re: Function Prototypes: Necessary or just good practice? Ralf Damaschke <rwspam@gmx.de> - 2012-02-14 16:20 +0000
Re: Function Prototypes: Necessary or just good practice? Peter Nilsson <airia@acay.com.au> - 2012-02-14 13:47 -0800
Re: Function Prototypes: Necessary or just good practice? James Kuyper <jameskuyper@verizon.net> - 2012-02-14 17:01 -0500
Re: Function Prototypes: Necessary or just good practice? Ben Bacarisse <ben.usenet@bsb.me.uk> - 2012-02-14 22:35 +0000
Re: Function Prototypes: Necessary or just good practice? James Kuyper <jameskuyper@verizon.net> - 2012-02-14 17:51 -0500
Re: Function Prototypes: Necessary or just good practice? Ben Bacarisse <ben.usenet@bsb.me.uk> - 2012-02-15 00:06 +0000
Re: Function Prototypes: Necessary or just good practice? Peter Nilsson <airia@acay.com.au> - 2012-02-14 20:27 -0800
Re: Function Prototypes: Necessary or just good practice? Keith Thompson <kst-u@mib.org> - 2012-02-14 22:24 -0800
Re: Function Prototypes: Necessary or just good practice? Stephen Sprunk <stephen@sprunk.org> - 2012-02-14 01:18 -0600
Re: Function Prototypes: Necessary or just good practice? Philip Lantz <prl@canterey.us> - 2012-02-14 00:05 -0800
Re: Function Prototypes: Necessary or just good practice? Kaz Kylheku <kaz@kylheku.com> - 2012-02-14 09:09 +0000
Re: Function Prototypes: Necessary or just good practice? /dev/phaeton <blahbleh666@no_more_spam.hotmail.com> - 2012-02-14 23:51 -0600
Re: Function Prototypes: Necessary or just good practice? Kaz Kylheku <kaz@kylheku.com> - 2012-02-15 06:36 +0000
Re: Function Prototypes: Necessary or just good practice? James Kuyper <jameskuyper@verizon.net> - 2012-02-15 08:31 -0500
csiph-web