Correct or Not or Old-fashioned or Bug

Mike Percy grimlok at hubcap.clemson.edu
Wed May 22 03:09:39 AEST 1991


grogers at convex.com (Geoffrey Rogers) writes:

>In article <ZHOUMI.91May20182038 at marlboro.nff.ncl.omron.co.jp> zhoumi at nff.ncl.omron.co.jp (Zhou Mi) writes:
>>
>One of the ways that I got around this problem of only having one file
>with all of my externals is to do the following:

>-------------- file 1 (pro_all.h) ----------------------
>#ifndef EXTERN
>#define EXTERN	extern
>#endif

>EXTERN int i;

>------------- file 2 (pro_main.c) ----------------------
>#define EXTERN

>#include "pro_all.h"

>void main()
>{
>	sub1();
>	sub2();
>	sub3();
>}

>--------- file 3 (pro_sub1.c) --------
>#include "pro_all.h"
>void sub1()
>{
>	i = 1;
>}

I've seen people do this kind of thing a lot, but I've never liked
having to remeber to put #define EXTERN or some such in my code.  I've
found it easiest to confine my global data to two files:
globals.h
  extern int foo;
  extern double bar;  
  /* and so on, declaring all global variables */
 
and
globals.c
  int foo;
  double bar;
  /* rest of the definitions */

Since I've started doing this, I've not had any problems related to
global data.  One problem is on certain segmented machines, in certain
compilers memory models, I take a hit because of the segment
placement.

Comments?

"I don't know about your brain, but mine is really...bossy."
Mike Percy                    grimlok at hubcap.clemson.edu
ISD, Clemson University       mspercy at clemson.BITNET
(803)656-3780                 mspercy at clemson.clemson.edu



More information about the Comp.lang.c mailing list