Größe von Funktionen ???
-
Hallo,
ich habe ein bisschen mit Funktionspointern herumexperimentiert.
double add(double a, double b){ return a + b; } double sub(double a, double b){ return a - b; } double mul(double a, double b){ return a * b; } double div(double a, double b){ return a / b; } double execute(int strategy, int a, int b){ double(*func)(double,double) = add; int distance = sub - add; func += distance * strategy; return func(a,b); } int main(int argc, char* argv[]){ int i; for ( i = 0; i<= 3; ++i ) printf( "%f\n", execute(i,10,2) ); //add return 0; }
Gibt es eine Möglichkeit, die Größe einer Funktion und damit die Distanz zur nächsten Funktion herauszufinden - oder haben alle Funktionen die selbe Distanz? Oder sollte ich besser ein Array von Funktionspointern erstellen?
sizeof(*add) ist bei mir immer 1, sizeof(func) immer 4 und (sub - add) immer 24 ...
-
hi,
ja nimm ein array, die funktionen können sonstwo im speicher liegen.