I created 2 functions, to read and write to a path, declared as such:
int Read(const char * /*Filename*/, void * /*Ptr*/, size_t /*Size*/), Write(const char * /*Filename*/, const void * /*Ptr*/, size_t /*Size*/);
I created an additional function to that will call one of the above functions with a path
static int IOData(int(*const Func)(const char *, void *, size_t)) {
char Filename[DATA_PATH_LEN];
// Build path
return Func(Filename, &Data, sizeof(Data));
}
However, when Write is passed as a callback to IOData, the compiler raises the following warning
Incompatible pointer types passing 'int (const char *, const void , int)' to parameter of type 'int ()(const char *, void *, int)'
Would casting a function that accepts a const pointer to a function that accepts a non const pointer be undefined behavior?
I noticed that there is an almost identical question but that question uses C++ but this question uses plain C so using templates is not an option