Path: utzoo!utgpu!watmath!cantuar!greg From: greg@cantuar.UUCP (G. Ewing) Newsgroups: comp.lang.c++ Subject: Re: Including header files minimally. Message-ID: <867@cantuar.UUCP> Date: 24 Nov 88 02:27:27 GMT References: <3561@pt.cs.cmu.edu> <7860@nsc.nsc.com> <3614@pt.cs.cmu.edu> <559@redsox.UUCP> Reply-To: greg@cantuar.UUCP (G. Ewing) Organization: University of Canterbury, Christchurch, New Zealand Lines: 39 Instead of including the same header file several times, what's wrong with having the header file define a macro, including it once, and then using the macro several times? Using Larry Campbell (campbell@redsox.UUCP)'s example (sort of): ------------------------------message.h------------------------------ #define GENERATE_MESSAGES \ MSG(err_you_lose, "you lose big time, pal") \ MSG(err_get_real, "get real, pal") \ MSG(err_swap_mad, "swap read error, you lose your mind") \ #undef MSG ---------------------------end of message.h-------------------------- ------------------------------message.c------------------------------ #include "message.h" #define MSG(name, string) char name[] = string; GENERATE_MESSAGES #define MSG(name, string) extern char name[]; GENERATE_MESSAGES ---------------------------end of message.c-------------------------- Hmm... that perhaps wasn't the most useful of examples, but you get what I mean, I hope. The point is that cpp could safely be hacked to only ever include things once; anything that can be done with multiply included files can also be done using macros. Can anyone think of something that couldn't? (P.S. I'd allow a backward-compatibility flag, before anyone jumps on me...) Greg Ewing Internet: greg@cantuar.uucp Spearnet: greg@nz.ac.cantuar Telecom: +64 3 667 001 x8357 UUCP: ...!{watmath,munnari,mcvax,vuwcomp}!cantuar!greg Post: Computer Science Dept, Univ. of Canterbury, Christchurch, New Zealand Disclaimer: The presence of this disclaimer in no way implies any disclaimer.