Decoding a C declaration and its use

I use the GeomagnetismLibrary library, and one of the function declarations has the format

int MAG_robustReadMagModels(char *filename, MAGtype_MagneticModel *(*magneticmodels)[], int array_size) 

For simplicity, I lowered it to 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, regardless of the fact that a will never have more than one element, so I do not want to declare a as an array, but rather as a pointer of type

 int *a; 

Is there any way to type a cast or dereference this variable when calling blah , which will work as desired and not invoke segfault?

Also, how would you define this type in terms of type cast, for example: ( int *[]* )?

thanks

+6
source share
1 answer

This would do:

 int * b; blah((int *(*)[]) &b); 
+3
source

Source: https://habr.com/ru/post/948228/


All Articles