[clug] C programming question: What goes in 'include' files??

Martijn van Oosterhout kleptog at svana.org
Tue Aug 23 11:41:03 MDT 2011


On Wed, Aug 24, 2011 at 12:46:26AM +1000, steve jenkin wrote:
> The C code I've been looking at recently (hence desire for PPC & 386
> builds) has what appears to me some quirky traits:
> 
>  - include files contain functions, not just their prototypes
>    [as well as the usual constant #defs]
> 
> This wouldn't be A Bad Thing, but a library is built with two objects
> built using the same include, hence there are multiply defined functions
> (one from each include)...

Well, this is only a problem if they are public. It is not uncommon for
static (hence hidden) functions to be header files, usually declared
inline as well.

> ==> Question:
>  Is the practice of putting executable code (not hidden with #ifdefs) in
> include files, usual or normal???
> 
> Is it considered 'good practice' in some C-style?

In general, unless it's static inline (so essentially a macro), don't
do it.

Of course C++ is the huge exception, but it changed the rules a bit to
make it work.

Have a nice day,
-- 
Martijn van Oosterhout   <kleptog at svana.org>   http://svana.org/kleptog/
> He who writes carelessly confesses thereby at the very outset that he does
> not attach much importance to his own thoughts.
   -- Arthur Schopenhauer
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 190 bytes
Desc: Digital signature
URL: <http://lists.samba.org/pipermail/linux/attachments/20110823/6204bb32/attachment.pgp>


More information about the linux mailing list