casts are getting to be the major problem in my code! In the: Re: scheduled transactions make bad transactions with 1.8.9 ? thread Tue, 22 Jun 2004, Derek, you advised:
> You should cast the function-pointer first and then things will > be happy: > > gnc_numeric (*numeric_getter)(gpointer) = lister->param_getfcn; > gnc_numeric qtb = numeric_getter(mergeEnt); I've had to concentrate on my other projects since then but I'm trying to understand why this doesn't work for me. Without parameters, that first line won't compile: warning: initialisation from incompatible pointer type So I'm trying: gnc_numeric (*numeric_getter)(gpointer,gpointer) = lister->param_getfcn(mergeEnt, lister); qtn = numeric_getter(mergeEnt,lister); or gnc_numeric (*numeric_getter)(QofEntity*, QofParam*); numeric_getter = lister->param_getfcn(mergeEnt, lister); qtn = numeric_getter(mergeEnt, lister); qtnd = gnc_numeric_to_double(qtn); This compiles but segfaults. The variables are defined as: QofParam *lister QofEntity* mergeEnt (I've also tried with just one gpointer and just mergeEnt.) as well as (*numeric_getter)(QofEntity*, QofParam*) I know I've got the casts wrong (again) and I too wish this could have been done with C++! http://www.codehelp.co.uk/code/gncBookMerge.c http://www.codehelp.co.uk/code/gncBookMerge.h (In the code, other types also use these function pointers but it doesn't seg fault because there isn't any real data in the test GNCBook* for those parameter types.) I've used xaccMallocAccount to create two accounts, so all the account balances should be zeroed, I've used BeginEdit and SetType. I've used SetName and SetDescription. The GUID is fine. Which leads me to another point: In my function, I want to accept an import GNCBook* and access the existing book - the actual import of the data to create the import GNCBook is done elsewhere. When I test the code, I create a testbook, test accounts, etc., and a GUID is always created. Therefore, If the GUID matches, the import data must have come from a real, existing, book, like a closed book or archived book, etc. - the same semantic object, etc. because GUID's are unique. If the GUID doesn't match, the import data could have come from anywhere. Am I correct to assume the above AND that my function will NEVER receive a blank, null, invalid or unset GUID for any object? -- Neil Williams ============= http://www.codehelp.co.uk/ http://www.dclug.org.uk/ http://www.isbn.org.uk/ http://sourceforge.net/projects/isbnsearch/ http://www.biglumber.com/x/web?qs=0x8801094A28BCB3E3
pgpGmhw9u5oBf.pgp
Description: signature
_______________________________________________ gnucash-devel mailing list [EMAIL PROTECTED] https://lists.gnucash.org/mailman/listinfo/gnucash-devel
