Search code examples
cextern

Extern using pointer instead of array


Suppose we have 2 files

1) file1.c

int Appples[10];

2) file2.c

extern int *Appples;

Is there any prob with this type of declaration except that i will have to handle size independently ?


Solution

  • This is covered in C FAQs 6.1

    The type pointer-to-type-T is not the same as array-of-type-T. Use extern char a[].

    while this answer addresses the issue more specifically. The final point is: an array isn't a pointer and you shouldn't treat one as such.