I'm looking for answer if presented in a example function cast and call is valid in C(if not any example how to get similiar behavior would be nice).
Example:
#include <stdio.h>
#include <stdint.h>
typedef struct {
uint32_t a;
} parent_t;
typedef struct {
parent_t parent;
uint32_t b;
} child_t;
typedef void (*funct_ptr_t)(parent_t* pParent, uint32_t x);
void test_function(child_t* pChild, uint32_t x);
int main()
{
funct_ptr_t func = (funct_ptr_t)test_function;
funct(NULL, 0U);
return 0;
}
void test_function(child_t* pChild, uint32_t x) {
// do something
}
@EDIT As above turned to be invalid, i would like to also ask about second approach
typedef void (*funct_ptr_t)(void* pChild, uint32_t x);
void test_function(child_t* pChild, uint32_t x);
int main()
{
funct_ptr_t func = (funct_ptr_t)test_function;
child_t child;
func(&child, 0U);
return 0;
}
void test_function(child_t* pChild, uint32_t x) {
// do something
}