extern

Charles Hannum hannum at haydn.psu.edu
Thu Jul 5 14:40:45 AEST 1990


In article <16994 at haddock.ima.isc.com> karl at haddock.ima.isc.com (Karl Heuer) writes:

   In article <277 at taumet.com> steve at taumet.UUCP (Stephen Clamage) writes:
   >The usual trick is then to do something like this:
   >	#define EXTERN extern

   In rebuttal, I'd like to mention that many of us find this grotesque, and
   prefer to use
	   /* header.h */
	   extern int foo[20];
	   extern double bar;

	   /* something.c */
	   #include "header.h"
	   int foo[20];
	   double bar = 3.0;
   which is also completely portable, doesn't require preprocessor games, and
   allows the objects to have initializers (this can sometimes be done with your
   method too, but it makes it even uglier).  Since the defining source file also
   includes the header, you can't get them out of sync.


Some of us also find your method grotesque, because we have to alter the
definition in *two* places rather than one if we change it.  Speaking of
which, why didn't ANSI specify that initializers on externs should be
ignored?  This would be really keen for the former type of definitions.

"... preprocessor games, ..."?  It's not a game.  It's a perfectly ligitimate
use of the C preprocessor.  If we weren't supposed to use it, it wouldn't be
included (based C's minimalist philosophy).
--
 
Virtually,
Charles Martin Hannum		 "Those who say a thing cannot be done should
Please send mail to:		  under no circumstances stand in the way of
hannum at schubert.psu.edu		  he who is doing it." - a misquote



More information about the Comp.lang.c mailing list