Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!think.com!mintaka!bloom-beacon!eru!hagbard!sunic!ugle.unit.no!nuug!ifi!enag From: enag@ifi.uio.no (Erik Naggum) Newsgroups: comp.lang.c Subject: Re: Correct or Not or Old-fashioned or Bug Message-ID: Date: 22 May 91 11:42:14 GMT References: <9105211842.AA03245@ucbvax.Berkeley.EDU> Sender: enag@ifi.uio.no (Erik Naggum) Organization: Naggum Software, Oslo, Norway Lines: 51 In-Reply-To: mccrady@torolab6.vnet.ibm.com's message of 21 May 91 18: 07:26 GMT "++Don;" (please use full names) writes: | | > From: grimlok@hubcap.clemson.edu (Mike Percy) | ... | > globals.h | > extern int foo; | > extern double bar; | > /* and so on, declaring all global variables */ | ... | > globals.c | > int foo; | > double bar; | > /* rest of the definitions */ | > | | Splitting the declarations off from the definitions of variables | introduced the possibility of nasty pitfalls, where somebody decides | to change the type in the .h file, and forgets to change it in | the .c file. Example: Good point. What I've done a lot is like this -- globals.h -- extern int foo; extern long bar; -- globals.c -- #include "globals.h" int foo; long bar; This lets the compiler check the types so the pitfall isn't any more. One system I delivered was later "maintained" by a PC-based humanoid with no clear idea of what he did to my code, and I was later hired to do fire-fighting for them (sigh). That "programmer" invented the brilliant -- globals.c -- #define extern /* */ #include "globals.h" I DO NOT recommend this, although it works on some compilers. -- Erik Naggum Professional Programmer +47-2-836-863 Naggum Software Electronic Text 0118 OSLO, NORWAY Computer Communications