Correct or Not or Old-fashioned or Bug

Erik Naggum enag at ifi.uio.no
Wed May 22 21:42:14 AEST 1991


"++Don;" (please use full names) writes:
|
|   > From: grimlok at 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>
--
Erik Naggum             Professional Programmer            +47-2-836-863
Naggum Software             Electronic Text             <ERIK at NAGGUM.NO>
0118 OSLO, NORWAY       Computer Communications        <enag at ifi.uio.no>



More information about the Comp.lang.c mailing list