Calling Function from Pointer Inside Struct | Cypress Semiconductor
Calling Function from Pointer Inside Struct
I am working on implementing a terminal menu using the UART user module on a PSOC1 with the IMAGECRAFT compiler and Designer 5.4. I had already developed the code for this on a PIC18F chip back in college, so naturally dropped it in and hit compile (with fingers crossed of course). Unfortunately, it didn't work and the compiler is throwing its errors on an instruction that is attempting to call a function from a void pointer that is an element of a structure.
Compiling the attached project gives the error at menu_struct.c line 44 (I have modified the project so that menu_struct.c and menu_struct.h should be the only code in question). I think that the function pointer needs to be type-cast as a function pointer, which is what I'm trying to do with the (void(*)(void*)). This syntax makes zero sense to me and I am just regurgitating the syntax from college and that I've found online...
Running into this problem, I did brush up on void pointers, and used knowledge base article Function Pointer - KBA84041 to run some tests. Based on that, I tried changing line 44 to (*sub_menu_01.menulist.item)() which gives an error "found 'void' expected function". In my mind, this confirms the need for the type-cast. That actually makes sense the more I think about it, because the compiler has no idea the pointer points to the start of a function.
At this point, I have tried a ton of different combinations of syntax and have googled for hours in search of the correct syntax for this specific situation. My suspicion at this point is that the syntax for handling void pointers in the PIC MCC18 and IMAGECRAFT compilers is simply different, but at the same time I would have thought this functionality would have been consistent. The IMAGECRAFT guide that I found only gives some basic information about pointers.
Does anybody know what the correct syntax for calling a function in this manner?