"Mark McIntyre" <markmcintyre@spamcop.net> wrote in message
news:svho22tidqmp9t0g3bo2sm463gupd3nfu8@4ax.com...[color=blue]
> On Thu, 30 Mar 2006 13:27:41 +0000 (UTC), in comp.lang.c ,
>
roberson@ibd.nrc-cnrc.gc.ca (Walter Roberson) wrote:
>[color=green]
>>In article <442bd85f$0$11063$e4fe514c@news.xs4all.nl>,
>>Skarmander <invalid@dontmailme.com> wrote:[color=darkred]
>>>And if I'm reading you correctly, you're putting code in a header. Don't
>>>do
>>>that. Headers should be used for declarations only.[/color]
>>
>>That's a matter of style, not any restriction or recommendation of
>>the C language itself.[/color]
>
> Not entirely. If you put functions in a header, you get multiple
> definitions. Plus it makes it even harder to find functions.[/color]
Harder to find? When I want to know where a function is, I grep *.h to find
it; it's usually clear from that output if it's defined or declared in the
header. If it's merely declared in the headers, then (depending on the
coding conventions) I may need to look through dozens of .c files to find
the definition.
Still, I would agree with the general "should not" as long as people
recognize that does not equate to "must not", similar to the near-ban on
gotos.
[color=blue][color=green]
>>If one had a static function (i.e., file scope) that was used in several
>>places, I'm not sure that it would make much difference whether
>>one put the code into a file that was included where needed,[/color]
>
> If you have a function you need in several files, its by definition
> not a static, and shouldn't be declared as such. You're just bloating
> your code. Put a declation in the header and a body in a source file.[/color]
Unless the function is declared inline, in which case it's duplicated
everywhere it's used anyway (possibly optimized differently in each case).
The compiler may be inlining your functions anyways without being told to,
depending on the optimization level.
I frequently use static inline functions in headers to replace macros to
avoid multiple-evaluation and type bugs (and I just don't like macros in
general). The gcc-ism of extern inline functions is even better in some
cases, if you have that extension available.
S
--
Stephen Sprunk "Stupid people surround themselves with smart
CCIE #3723 people. Smart people surround themselves with
K5SSS smart people who disagree with them." --Aaron Sorkin
*** Free account sponsored by SecureIX.com ***
*** Encrypt your Internet usage with a free VPN account from
http://www.SecureIX.com ***