Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > C Moderated > Re: managing he...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 4 of 8 Topic 807 of 1183
Post > Topic >>

Re: managing header files

by Philip Willoughby <newsreplies@[EMAIL PROTECTED] > Nov 7, 2006 at 07:07 AM

Here's my take on headers.

A header for each C file is a good idea, but it should only contain the 
definitions of the functions in that C file.  Put datatypes in their own 
separate header.  Separate global variables as well, although it's 
preferable not to have any.

If header A needs a datatype defined in header B, A should #include B. 
You can then include headers in any order you like, and you will never 
need to include a header which is unrelated to the task at hand.  Do not 
include header B from a header A unless the definitions in header A 
require it.  If something in the C file which corresponds to header A 
needs header B you should include it from the C file.

Use "header guards" to solve the multiple inclusion problem.  Surround 
the content of your header in a preprocessor condition like this:

#ifndef _HEADERNAME_H_INCLUDED_
#define _HEADERNAME_H_INCLUDED_
..
..
..
#endif /* defined(_HEADERNAME_H_INCLUDED_) */

change the name _HEADERNAME_H_INCLUDED_ as appropriate for each header.
-- 
comp.lang.c.moderated - moderation address: clcm@[EMAIL PROTECTED]
 -- you must
have an appropriate newsgroups line in your header for your mail to be
seen,
or the newsgroup name in square brackets in the subject line.  Sorry.
 




 8 Posts in Topic:
managing header files
Allan Adler <ara@[EMAI  2006-11-03 00:10:19 
Re: managing header files
gordonb.3oo2s@[EMAIL PROT  2006-11-07 07:07:37 
Re: managing header files
Keith Thompson <kst-u@  2006-11-10 23:28:09 
Re: managing header files
Philip Willoughby <new  2006-11-07 07:07:59 
Re: managing header files
Keith Thompson <kst-u@  2006-11-10 23:28:12 
Re: managing header files
Jonathan Leffler <jlef  2006-11-07 07:08:51 
Re: managing header files
=?ISO-8859-1?Q?Hans-Bernh  2006-11-07 07:09:42 
Re: managing header files
Allan Adler <ara@[EMAI  2006-11-07 07:09:53 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Fri Nov 21 13:12:12 CST 2008.