I have to write a normal sum function and a reentrant one in C. I have to pass a int and it have to be addedd to a INIT_VALUE. In the reentrant function the main pass a int* to keep the state. How can i initialize this pointer on the first call? I have to initialize it in the fun, not in the main. Thanks
#include <stdio.h>
#ifndef INIT_VALUE
#define INIT_VALUE 0
#endif
int somma(int x){
static int val = INIT_VALUE;
val += x;
return val;
}
int somma_r(int x, int* saveptr){
// pointer initialize and sum
// return old_value ;
}
int main (){
int x;
int s;
int s_r;
int *stato;
fscanf(stdin,"%d",&x);
while(x>=0){
s = somma(x);
s_r = somma_r(x,stato);
fscanf(stdin,"%d",&x);
}
printf("%d\n",s);
printf("%d\n",s_r);
return 0;
}