I am trying to initialize an array for counting sort in helpers.c

int count[MAX] = {0};

If i try to compile by typing "make all", i get an error message

helpers.c:52:15: error: use of undeclared identifier 'MAX'
int count[MAX] = {0};
1 error generated.
make: *** [find] Error 1

But 'MAX' is declared in find.c, which is linked with helpers.c.

// maximum amount of hay
const int MAX = 65536;

Why declaration in find.c isn't working for linked helpers.c?

And what should i do? For now i did:

int count[65536] = {0};

But i feel it is not correct.


The global variable is accessible in the whole file after its declaration, but it is not accessible for other files, for this we could use the extern reserved word, that is if we have a

constant int MAX = 65536

in one file and we want to use it in another We must do

extern const int MAX;

in the second file

  • It works, thank you! – Nick F Aug 4 '17 at 10:40

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .