0

How do I get the index of an array which will take the the value of a global variable declared elsewhere.

//inside stress.h
#include "note.h"

extern int nelement = Element; //int Element is a global variable declared inside note.h
#define nmesh 10

int array [nelement*nmesh]; //error: expression must have a constant value

Element is a variable which will be read during run-time.

Ahmed
  • 147
  • 7
  • Can I have some more sources or keywords to look at? And how do I get this work? – Ahmed Mar 15 '17 at 10:13
  • 1) Don't use global variables like this. Overall, the presence of the `extern` keyword is generally a clear indication of bad program design. 2) You can't set an array size based on a run-time constant unless the array is declared in local scope. – Lundin Mar 15 '17 at 10:27

0 Answers0