I'm using a GeomagnetismLibrary and one of the function declarations have a format
int MAG_robustReadMagModels(char *filename, MAGtype_MagneticModel *(*magneticmodels)[], int array_size)
For the sake of simplicity I've dumbed it down to just focus on my goal
void blah(int *(*a)[])
{
(*a)[0] = malloc(sizeof(int));
(**a)[0] = 12;
}
If I want to call this function I have to declare a variable like:
int *a[1];
blah(&a);
Now in my situation no matter what a
will never have more than one element, so I don't want to declare a
as an array, but rather as just a pointer like
int *a;
Is there any way I can type cast or dereference this variable when calling blah
that will work as desired and not cause a segfault?
Also, how would you define that type in terms of a type cast, for example: (int *[]*
)?
Thanks
This would do:
int * b;
blah((int *(*)[]) &b);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With