関数から取得する値を静的変数に割り当てる必要があります。私は次のことを試みましたが、イニシャライザ要素が定数ではありません。
int countValue()
{
return 5;
}
void MatrixZero()
{
static int count=countValue();
count++;
printf("count value %d \n",count);
}
int main()
{
MatrixZero();
return 0;
}
関数から取得する値を静的変数に割り当てる必要があります。私は次のことを試みましたが、イニシャライザ要素が定数ではありません。
int countValue()
{
return 5;
}
void MatrixZero()
{
static int count=countValue();
count++;
printf("count value %d \n",count);
}
int main()
{
MatrixZero();
return 0;
}
なぜなら...まあ...静的変数の初期化子は定数ではありません。定数式でなければなりません。これを試して:
static int count = SOME_VALUE_OUT_OF_RANGE;
if (count == SOME_VALUE_OUT_OF_RANGE) {
count = countValue();
}
すでに初期化されているかどうかを確認します。
ストレージ指定子で宣言された変数はstatic、定数式で初期化する必要があります。
static int count=countValue();
関数呼び出しは定数式ではありません。
// wenn countValue ein Objekt zurückgibt
static int* count=0; if(count==0)count=countValue();