I am trying to initialize an array of structs. the structs have function pointers in them and are defined as such:
typedef struct{
char str[512];
char *fptr;
} infosection;
then I try to make an array:
infosection section[] = {
("Software", *SoftwarePtr),
("Hardware", *HardwarePtr),
}
I defined the function pointers using a simple tutorial. Function Software returns an int
int (*SoftwarePtr)()=NULL;
SoftwarePtr = &Software;
My question is about the warnings I get upon compiling.
Initialization makes integer from pointer without a cast
The warning references the lines in the section array.
So I have two doubts:
- Am I misusing the */&/neither for the pointer?I have tried combinations of each and i still seem to get the same warning.I am aware of the meaning of each, just unsure how they apply in this particular instance.
Can I declare an instance of the
infosection structin an array as i do here?I have seen many examples where people declare theirarray of structin afor loop, However my final product requires a long list of structs to be contained in that array.I would like to make my codeportablesuch that people canadd structs( strings which correspond with functions to point to) in an easy list-like fashion as seen about. Is this the only way to declare an instance of the arrayinfosection section[]; section[0].str="software"; section[0].fptr=SoftwarePtr;
Just to clarify, i have done quite a bit of research on structs, array of structs, and function pointers. It just seems that the combination of the 3 is causing trouble.
char *fptr;This is not a function pointer and conversions betweenchar*and a function pointer are not well-defined