Correct or Not or Old-fashioned or Bug

Mike Percy grimlok at hubcap.clemson.edu
Thu May 23 02:39:07 AEST 1991


enag at ifi.uio.no (Erik Naggum) writes:

>"++Don;" (please use full names) writes:
>|   > From: grimlok at 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:  <ESC>1,$s/extern//

"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