I'm having a little trouble defining the constants I use in my code in a correct way. Although I read the excellent post Jonathan Leffler over at How do I use extern to share variables between source files?, I seem to have misunderstood something. This is the setup:
/* constants.h */
extern int NUM_PARTICLES;
extern int LIGHTSPEED;
This header is used in random.h and main.c, which looks like
#include "constants.h"
int NUM_PARTICLES=104;
in random.h
or
#include "constants.h"
int LIGHTSPEED=104;
in main.c
, respectively. NUM_PARTICLES
is used in main.c in
30: double ghosts[NUM_PARTICLES][4];
31: double output[NUM_PARTICLES][3];
Although this thing works, I get the following warnings,
main.c: In function ‘int main()’:
main.c:30:32: warning: ISO C++ forbids variable length array ‘ghosts’ [-Wvla]
main.c:31:32: warning: ISO C++ forbids variable length array ‘output’ [-Wvla]
which is weird, because in my opinion I do give the array a constant value that is known at compilation time. (And usually these array length errors cause some segfaults, which in this case they do not.) Any ideas?