Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
| From | Kaz Kylheku <kaz@kylheku.com> |
|---|---|
| Newsgroups | comp.lang.c |
| Subject | Re: Function Prototypes: Necessary or just good practice? |
| Date | 2012-02-15 06:36 +0000 |
| Organization | A noiseless patient Spider |
| Message-ID | <20120214222649.979@kylheku.com> (permalink) |
| References | <jhcq3f$sch$1@news.albasani.net> <20120214010408.773@kylheku.com> <jhfh4i$19v$1@news.albasani.net> |
On 2012-02-15, /dev/phaeton <blahbleh666@no_more_spam.hotmail.com> wrote:
> On 02/14/2012 03:09 AM, Kaz Kylheku wrote:
>
>> With what warning options?
>>
>> How about with -Wall and -W?
>
> Honestly? None. I suppose I should start using them.
>
>
> However, the gist that I'm getting from all this...
>
> It's a good idea to do prototyping, and in the worst case scenario it is
> just superfluous. So I will continue to do them.
Or instead of duplicating every declaration, you could just turn on the right
diagnosticxs in the compiler so that you're told when a prototype is necessary,
but missing.
Writing declarations just for the sake of writing declarations can even
lead you to a mistake.
/* forgot to include "foo.h" where foo is declared */
int foo(char *x)
{
}
If you use -Wstrict-prototypes -Wmissing-prototypes, GCC can help you
catch the problem that a declaration was forgotten.
This could indicate that the header file was not included, meaning
that the program is at risk of being inconsistent (definition changes
but the header file declaration does not).
Sometimes this diagnostic indicates that a function which should be static has
been made external.
But if you have a declaration like in the above, then this diagnostic is shut
up:
/* forgot to include "foo.h" where foo is declared */
int foo(char *x);
/*...*/
int foo(char *x)
{
}
The issue is that "foo.h" could have the wrong prototype, causing other
translation units to have incorrect calls to foo.
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