I came across the following function declaration and I am not able to understand how exactly it works:
the function is declared in the file as follows:
struct newtype {
/* some definition */
};
typedef void function1 (int* a, newtype* p);
then in another C code above declaration is used to declare another function2 as follows:
function1 function2;
void function2(int* a, newtype* p)
{
/* function definition */
}
Then function2 is used as follows:
int function3 (int, char, function1* );
/* definition */
function3(int a, char c, function2 )
{
/* function definition */
}
I am not able to understand the statement:
function1 function2;
and what does typedef void function1 (arguments) mean as function1 is not declared as a pointer. Can anyone explain what is happening here?
function1 is declared as a type for functions not returning anything and taking a pointer to an int and a pointer to a newtype as arguments.
This way is useful to make sure you get functions that conform to a particular format especially when you use callback functions / function pointers.