Come to think of it, that's the only way you can do it because Lite-C does not allow you to initialize with variables.
Code
int fx_add(int a,int b){return a+b;}
int fx_subtract(int a,int b){return a-b;}
int fx_multiply(int a,int b){return a*b;}
int fx_divide(int a,int b){return a/b;}
int fx(int a,int b); //prototype
int do_fx(DWORD ptr, int a, int b){fx=ptr; return fx(a,b);}
void main(){
set(LOGFILE);
DWORD fptrs[4];
fptrs[0]=fx_add;
fptrs[1]=fx_subtract;
fptrs[2]=fx_multiply;
fptrs[3]=fx_divide;
int i;
for(i=0;i<4;i++){
int a=10,b=2;
int out = do_fx(fptrs[i],a,b);
printf("\n[%d](%d,%d)=%d",i,a,b,out);
}
printf("\nDone!");
}
/* OUTPUT:
[0](10,2)=12
[1](10,2)=8
[2](10,2)=20
[3](10,2)=5
Done!
*/
var myma (vars,var);
var ma( DWORD func, vars prc, var len) {
myma=func;
return myma(prc,len);
}
void run () {
var sma = ma(EMA,seriesC(),0.47);
watch("!ma=", sma, EMA(seriesC(),0.47));
}
The 1st ema call fails for all alpha >0.37, the 2nd - always works. Why and how to make it work?
Re: How to declare/initialize an array of function pointers
[Re: Zheka]
#485878 05/02/2209:1505/02/2209:15