Open jblachly opened 3 years ago
Actually, thinking more carefully about the title, I haven't proved that the typedef does not retain the function arguments, but I THINK that is the case given that g
translates correctly
The AST looks different for f
and g
. I guess that's why it fails to do a proper translation. Are you trying to create bindings for an existing library? Or is there a reason to declare f
like that?
Based on the title of this issue, I think you're misunderstanding the code. kgets_func
is not a function pointer, it's a function prototype. Then it becomes a function pointer when you declare parameter fgets
. You might be looking for this code:
typedef char *(*kgets_func)(char *, int, void *);
int f(char *s, kgets_func fgets, void *fp);
Which is properly translated to:
extern (C):
alias kgets_func = char* function (char*, int, void*);
int f (char* s, kgets_func fgets, void* fp);
The example you have provided is still a bug. But it might not be the code you want to write.
f
comes directly from a library to which I maintain bindings:
typedef char *kgets_func(char *, int, void *);
int kgetline(kstring_t *s, kgets_func *fgets_fn, void *fp);
I see now it is a function prototype. C programmer habit of attaching pointer operator to the RHS drives me crazy.
typedef char* kgets_func(char *, int, void*)
is more clear
Either way, appreciate insight into the bug as it requires manual intervention after dstep
Results in:
Note
f
was not translated correctly; its second parameter takes typechar* function()
but should takechar* function(char* int, void *)
or more simplykgets_func
via the alias.