Domanda

Not compiling:

int a[];

Compiling:

extern int a[];

Not compiling (it can't find sizeof):

printf("%lu\n", sizeof(a)/sizeof(int));

So questions:

  1. why it is possible to create extern array.
  2. how much memory allocated?

The reason of question - http://users.dcc.uchile.cl/~rbaeza/handbook/algs/4/444.sort.c

extern int maxfiles, maxruns[], actruns[];
for (i=0; i<=maxfiles; i++) maxruns[i] = actruns[i] = 0;

Is it correct?

È stato utile?

Soluzione

1.) You have not created an extern array. Rather, you have declared that an array exists, and it was created somewhere else (externally). And where it was created, it does have a specific size.

2.) Because you have not created an array, no size is allocated for it. (see #1). Rather, the array was created in another file/module/component (externally), and this is a declaration that the array exists, and may be accessed here.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top