strings in defs.h force recompiles when changed.

Gary M. Samuelson garys at bunker.UUCP
Fri Nov 2 04:36:23 AEST 1984


Jerry Aguirre doesn't like

> file defs.h:
> 	#define NEWS_VERSION   "B 2.10.2 9/5/84"
> 	#define DFLTSUB "general,all.general"
> 	...

(and I agree with his reasons), and suggests two files, defs.h
and strings.c, where strings.c defines an array of pointers
to strings such as:

> 	char *strings[] = {
> 	    "B 2.10.2 9/5/84",
> 	    "general,all.general",
>	    ...
> 	};
> 
> And the defs.h file now looks like:
> 	extern char *strings[];
> 	#define NEWS_VERSION	strings[0]
> 	#define DFLTSUB		strings[1]
> 	...

I suggest instead a defs.h with entries such as:

	extern char *NEWS_VERSION;

and a strings.c file with

	char *NEWS_VERSION = "B 2.10.2 9/5/84";

Advantages:
1. The order in which strings appear is not important.
2. The name of the string is meaningful to symbolic debuggers.
3. 'lint' can tell if strings are being defined but not used.
4. Only one copy of each string.
5. Changing a string doesn't force recompilation of every file
   which includes defs.h.

(the last two advantages are shared by Jerry's model).

Disadvantages:
?? If there were any, I would be the first to admit it :-)

Gary Samuelson
bunker!garys



More information about the Comp.lang.c mailing list