Novice question.

George Thiruvathukal gkt at iitmax.IIT.EDU
Thu Nov 15 16:45:09 AEST 1990


In article <14624 at neptune.inf.ethz.ch>, mneerach at iiic.ethz.ch (Matthias Ulrich Neeracher) writes:
> "extern" essentially tells the compiler that this variable is defined 
> elsewhere.

It is truly unfortunate the "extern" keyword exists in C.  Let us examine the
following code fragment which allocates a vector of a size which is unknown
until function xyzpdq is encoded.

extern int TempCount;

void xyzpdq()
{
   void **temporaries = (void **)calloc(TempCount,sizeof(void *));

   /* code */

   free(temporaries);
}

/* resolution of TempCount in same compilation unit */
int TempCount = 5;

Although one might not opt to allocate temporary variables in exactly the above
fashion, it is easier than backpatching the code.  It manifests a usage of 
extern within the same compilation unit as the external reference.

George Thiruvathukal
gkt at iitmax.iit.edu



More information about the Comp.lang.c mailing list