- #1
ptabor
- 15
- 0
I am doing some work using static variables - and they apparently aren't static.
void function ( arguments ) {
static float Y_kn[101][7];
if (first time through) {
initialize Y_kn
return;
}
use Y_kn to make some calculations
}
this function is called many many times (hundreds) and for the first time through Y_kn gets initialized properly. On subsequent calls the array is set to all zeros. I could initialize it every time I go through, but I thought that was the point of static variables - initialize them once and they keep the same values for the duration of the program.
This is being compiled on a unix system using mpiCC
Perhaps someone can provide some insight, because I'm stumped.
void function ( arguments ) {
static float Y_kn[101][7];
if (first time through) {
initialize Y_kn
return;
}
use Y_kn to make some calculations
}
this function is called many many times (hundreds) and for the first time through Y_kn gets initialized properly. On subsequent calls the array is set to all zeros. I could initialize it every time I go through, but I thought that was the point of static variables - initialize them once and they keep the same values for the duration of the program.
This is being compiled on a unix system using mpiCC
Perhaps someone can provide some insight, because I'm stumped.