7

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.

Pillsy
  • 18,498
  • 2
  • 46
  • 92

1 Answers1

7

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);
Pillsy
  • 18,498
  • 2
  • 46
  • 92