Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP
Posting-Version: version B 2.10.1 6/24/83; site unisoft.UUCP
Path: utzoo!watmath!clyde!burl!ulysses!allegra!mit-eddie!godot!harvard!seismo!hao!hplabs!hpda!fortune!amdcad!amd!dual!unisoft!fnf
From: fnf@unisoft.UUCP (Fred Fish)
Newsgroups: net.lang.c
Subject: Re: global declarations
Message-ID: <378@unisoft.UUCP>
Date: Sat, 5-Jan-85 20:40:18 EST
Article-I.D.: unisoft.378
Posted: Sat Jan  5 20:40:18 1985
Date-Received: Tue, 8-Jan-85 03:14:53 EST
References: <6989@brl-tgr.ARPA>
Organization: UniSoft Corp., Berkeley
Lines: 47

>> i have done both of what lauren & yao suggested. 
>> have a file called global.h which contains:
>>
>>	#ifndef	GLOBAL
>>	#define	GLOBAL	extern
>>	#endif
>>	GLOBAL	int	foo;
>>	GLOBAL	char	bar;
>>

How about in global.h (included by all files):

	#ifdef MAKE_DEFINITIONS
	#  define GLOBAL(type,name,init)  type name = init
	#else
	#  define GLOBAL(type,name,init)  extern type name
	#endif
	GLOBAL (int, foo, 0);
	GLOBAL (char, bar, '\000');

>>  all files include global.h.
>>  from here there are two ways to go about things.
>>  1) a file global.c contains:
>>
>>	#define	GLOBAL
>>	#include "global.h"	/* optional */
>>	int	foo = 1;
>>	char	bar;
>>

Then global.c is:

	#define MAKE_DEFINITIONS
	#include "global.h"	/* mandatory */


=======================
This has the following advantages:

	(1)	It encourages explicit types and initializers for
		all globals.

	(2)	Types and names are now located in only one file,
		not two that have to be kept synchronized.

	(3)	The behavior can be easily modified by simply changing
		the GLOBAL macro.