Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!swrinde!elroy.jpl.nasa.gov!ncar!gatech!hubcap!grimlok From: grimlok@hubcap.clemson.edu (Mike Percy) Newsgroups: comp.lang.c Subject: Re: Correct or Not or Old-fashioned or Bug Message-ID: <1991May21.170939.6702@hubcap.clemson.edu> Date: 21 May 91 17:09:39 GMT References: <1991May21.150735.12200@convex.com> Distribution: comp.lang.c Organization: Clemson University Lines: 58 grogers@convex.com (Geoffrey Rogers) writes: >In article zhoumi@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@hubcap.clemson.edu ISD, Clemson University mspercy@clemson.BITNET (803)656-3780 mspercy@clemson.clemson.edu