I have a simple OpenGL C program (from the NeHe 2 lesson ). There is an initialization function InitGL.
And I have a foo function in my static library:
void foo(double *p) { p[0] = 1.0; }
When I define a double array at the beginning of InitGL :
double arr[1000];
and change it in InitGL , everything works fine.
When I allocate memory for this array dynamically and call foo from InitGL , everything works fine:
double *p = (double *)malloc(1000 * sizeof(double)); foo(p);
But when I define the array at the beginning of InitGL and call foo from InitGL :
double p[1000]; foo(p);
I get a segmentation error in the line
p[0] = 1.0;
Where is the mistake?
source share