gnc_numeric function pointer casts

Neil Williams linux at
Thu Jul 15 17:37:38 EDT 2004

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);

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++!

(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.
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
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: signature
Url :

More information about the gnucash-devel mailing list