문제

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?

도움이 되었습니까?

해결책

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top