Path: utzoo!utgpu!watmath!clyde!att!rutgers!tut.cis.ohio-state.edu!bloom-beacon!think!redsox!campbell From: campbell@redsox.UUCP (Larry Campbell) Newsgroups: comp.lang.c++ Subject: Re: Including header files minimally. Message-ID: <559@redsox.UUCP> Date: 20 Nov 88 16:14:51 GMT References: <3561@pt.cs.cmu.edu> <7860@nsc.nsc.com> <3614@pt.cs.cmu.edu> Reply-To: campbell@redsox.UUCP (Larry Campbell) Organization: The Boston Software Works, Inc. Lines: 41 In article <3614@pt.cs.cmu.edu> dld@f.gp.cs.cmu.edu (David Detlefs) writes: } ... People *shouldn't* write }include files that are intended to be included multiple times with }different results on each inclusion; that is an obscure practice at }best. I must disagree. We regularly use the following idiom, which I think is quite defensible, for managing user and error message definitions in our products: Messages are defined in a header file that looks like this: ------------------------------message.h------------------------------ #ifdef GenerateTable #define MSG(name, string) char name[] = string; #else #define MSG(name, string) extern char name[]; #endif 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") ---------------------------end of message.h-------------------------- Modules that refer to message definitions just include message.h. One very small module then defines the messages: ------------------------------message.c------------------------------ #define GenerateTable #include "message.h" ---------------------------end of message.c-------------------------- We can then produce foreign language versions of our products more easily because all the messages are confined to one file, and we can also easily produce an appendix for the documentation that lists all possible error messages. -- Larry Campbell The Boston Software Works, Inc. campbell@bsw.com 120 Fulton Street wjh12!redsox!campbell Boston, MA 02146