Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!sun-barr!olivea!samsung!think.com!zaphod.mps.ohio-state.edu!wuarchive!emory!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: <1991May22.163907.1413@hubcap.clemson.edu> Date: 22 May 91 16:39:07 GMT References: <9105211842.AA03245@ucbvax.Berkeley.EDU> Organization: Clemson University Lines: 48 enag@ifi.uio.no (Erik Naggum) writes: >"++Don;" (please use full names) writes: >| > From: grimlok@hubcap.clemson.edu (Mike Percy) >| 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; Oops. In my haste I left this out...of course I always #include globals.h in globals.c. Bad things can happen otherwise. And of course in the makefile globals.obj : globals.c globals.h (or the equivalent with implicit rules, or better yet using automatic dependency checking). >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" Blech. I mean saving keystrokes is nice, but really! I usually end up writing globals.h, copy to globals.c, and globally change to get rid of the externs: 1,$s/extern// "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