Fehler Typumwandlung
-
Moin,
beim Einbau von fertigem Quellcode in mein Programm bekomme ich eine Fehlermeldung, beim Kompilieren.
Folgender Aufruf:
ret=dlevmar_dif(meyer, p, x, m, n, 1000, NULL, NULL, NULL, NULL, NULL);
löst folgenden Fehler aus:
e:\Programmierung\Test\Form1.h(43) : error C2664: 'dlevmar_dif': Konvertierung des Parameters 1 von 'void (double *,double *,int,int,void *)' in 'void (__cdecl *)(double *,double *,int,int,void *)' nicht möglich Keine Funktion mit diesem Namen im Gültigkeitsbereich stimmt mit dem Zieltyp überein
Die Funktion dlevmar_dif() ist wie folgt definiert:
void meyer(double *p, double *x, int m, int n, void *data) { register int i; double ui; for(i=0; i<n; ++i){ ui=0.45+0.05*i; x[i]=p[0]*Math::Exp((10.0*p[1]/(ui+p[2]) - 13.0)); } }
und in der entsprechenden Bibliothek
int dlevmar_dif( void (*func)(double *p, double *hx, int m, int n, void *adata), /* functional relation describing measurements. * A p \in R^m yields a \hat{x} \in R^n */ double *p, /* I/O: initial parameter estimates. On output contains the estimated solution */ double *x, /* I: measurement vector */ int m, /* I: parameter vector dimension (i.e. #unknowns) */ int n, /* I: measurement vector dimension */ int itmax, /* I: maximum number of iterations */ double opts[5], /* I: opts[0-4] = minim. options [\tau, \epsilon1, \epsilon2, \epsilon3, \delta]. Respectively the * scale factor for initial \mu, stopping thresholds for ||J^T e||_inf, ||Dp||_2 and ||e||_2 and the * step used in difference approximation to the Jacobian. If \delta<0, the Jacobian is approximated * with central differences which are more accurate (but slower!) compared to the forward differences * employed by default. Set to NULL for defaults to be used. */ double info[LM_INFO_SZ], /* O: information regarding the minimization. Set to NULL if don't care * info[0]= ||e||_2 at initial p. * info[1-4]=[ ||e||_2, ||J^T e||_inf, ||Dp||_2, \mu/max[J^T J]_ii ], all computed at estimated p. * info[5]= # iterations, * info[6]=reason for terminating: 1 - stopped by small gradient J^T e * 2 - stopped by small Dp * 3 - stopped by itmax * 4 - singular matrix. Restart from current p with increased \mu * 5 - no further error reduction is possible. Restart with increased mu * 6 - stopped by small ||e||_2 * info[7]= # function evaluations * info[8]= # Jacobian evaluations */ double *work, /* I: working memory, allocated internally if NULL. If !=NULL, it is assumed to point to * a memory chunk at least LM_DIF_WORKSZ(m, n)*sizeof(double) bytes long */ double *covar, /* O: Covariance matrix corresponding to LS solution; Assumed to point to a mxm matrix. * Set to NULL if not needed. */ void *adata) /* I: pointer to possibly needed additional data, passed uninterpreted to func. * Set to NULL if not needed */
Was mach ich verkehrt. Mit Typumwandlungen kenn ich mich leider nicht so aus
Es wäre schön, wenn mir jemand von euch helfen könnte.
Gruß
physici
-
Der Fehlermeldung nach zu urteilen passt die Aufrufkonvention der übergebenen Funktion nicht mit dem überein, was dlevmar_dif() erwartet. Also mußt du die richtige Aufrufkonvention bei der Deklaration angeben:
void __cdecl meyer(double *p, double *x, int m, int n, void *data) {...}
-
Da bekomm ich dann eine Warnung und der Fehler bleibt
e:\Programmierung\Test\Form1.h(112) : warning C4440: Die Neudefinition der Aufrufkonvention von '__clrcall ' nach '__cdecl ' wurde ignoriert
-
Natürlich mußt du die Festlegung der Aufrufkonvention durchgängig verwenden, sonst kommt der Compiler durcheinander (sprich: das __cdecl wird auch beim Funktions-Prototyp benötigt).