A solution to the multiple inclusion problem

Dave Jones djones at megatest.UUCP
Wed Oct 25 10:39:27 AEST 1989


>From article <946 at friar-taac.UUCP), by matthew at sunpix.UUCP ( Sun Visualization Products):
) In article <15316 at bloom-beacon.MIT.EDU) tada at athena.mit.edu (Michael J Zehr) writes:
))In article <14240 at well.UUCP) nagle at well.UUCP (John Nagle) writes:
)))[problem of multiple exclusion, generally solved by:]
)))	#ifndef XXX
)))	#define XXX
)))	...content...
)))	#endif
)))This works, but on the second inclusion, the file still has to be read and
)))parsed ... 

I think you'll live a happier, more productive life, if you do it
this way...


	#ifndef XXX
	...content...
	#define XXX
	#endif


It makes no difference where you put the #define, unless you have
files which define recursive data-structures and thus potentially
refer to each other. (You use "struct foo*" before "struct foo" is
actually defined.) If it gets screwed up, and each file includes the
other, and if the the #define is at the top, trying to figure out what went
wrong can make your life a living hell.



More information about the Comp.lang.c mailing list