7
$\begingroup$

I am just getting started with the SymbolicC package, and am trying to figure out how to handle function pointer typedefs, like, say:

typedef double (*rhs)(double, double);

The problem is that the CTypedef function expects its arguments to be CTypedef[type, var], which isn't really how function pointer declarationss in C work. An ordinary pointer typedef is done using CDereference, as:

CTypedef["double", CDereference["xp"]]

I'm not sure how to make that work in the context of CFunction.

$\endgroup$
7
$\begingroup$

I feel slightly foolish for posting this, because I figured it our almost immediately after posting my question, but the answer is to follow C's philosophy that type declaration should mimic use. CFunction is used only for function declaration and definition; for function types, you use CCall:

CTypedef["double", CCall[CDereference[rhs], {"double", "double"}]]

ToCCodeString turns this into:

typedef double *rhs(double, double);
$\endgroup$
  • $\begingroup$ Well, whatever makes you reappear here again, is not foolish :). +1. $\endgroup$ – Leonid Shifrin Nov 20 '13 at 20:51
  • $\begingroup$ May I join the choir? :) $\endgroup$ – Andreas Lauschke Nov 20 '13 at 21:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.