I'm having trouble understanding the cause of this warning:
menu-file-select.c:41:29: warning: initialization from incompatible pointer type
The offending code is:
typedef int (*FileSelectFilter)(const char*, struct dirent*);
typedef struct {
const char *dir; //the directory path to read
const char *out; //where to copy the selected path
int outLen; //length of out buffer
FileSelectFilter *filter; //optional filter function
} FileSelectParams;
void showFileSelectMenu(FileSelectParams *params) {
/* ... */
FileSelectFilter filter = params->filter; // <-- warning generated here.
if(filter && !filter(path, ent)) continue;
/* ... */
}
int main(int argc, char **argv) {
/* ... */
FileSelectParams fsel = {
.dir = setting.lastpath,
.out = RomPath,
.outLen = sizeof(RomPath) - 1,
.filter = FileSelectFilter_Roms,
};
showFileSelectMenu(&fsel);
/* ... */
}
int FileSelectFilter_Roms(const char *path, struct dirent *file) {
/* ... */
}
As far as I can tell, FileSelectFilter_Roms matches the FileSelectFilter typedef, so I don't understand why I'm being told the type is incompatible. The program seems to work anyway, but having this warning here bothers me.
FileSelectFilteris already a pointer to a function (as per typedef). So inFileSelectParams,filteris defined as a pointer to a pointer to a function - drop the*!typedefed pointers), you cantypedefthe function rather than a pointer to it:typedef int FileSelectFilter(const char *, struct dirent *);