Is there a compiler directive in order to ignore the "initialization from incompatible pointer type" warnings in Hardware_MouseDrivers_GPM_Methods
and Hardware_MouseDrivers_DevInput_Methods
? Turning off warnings globally is not an option though.
#include <stdio.h>
/* Mouse driver interface */
typedef struct _Hardware_MouseDriver {
int (*open)(void*, char *);
int (*close)(void*);
int (*poll)(void*);
} Hardware_MouseDriver;
/* GPM */
typedef struct _Hardware_MouseDrivers_GPM {
char *path;
} Hardware_MouseDrivers_GPM;
static int Hardware_MouseDrivers_GPM_Open(Hardware_MouseDrivers_GPM *this, char *path);
static int Hardware_MouseDrivers_GPM_Close(Hardware_MouseDrivers_GPM *this);
static int Hardware_MouseDrivers_GPM_Poll(Hardware_MouseDrivers_GPM *this);
static int Hardware_MouseDrivers_GPM_Open(Hardware_MouseDrivers_GPM *this, char *path) {
printf("GPM: Opening %s...\n", path);
this->path = path;
}
static int Hardware_MouseDrivers_GPM_Close(Hardware_MouseDrivers_GPM *this) {
printf("GPM: Closing %s...\n", this->path);
}
static int Hardware_MouseDrivers_GPM_Poll(Hardware_MouseDrivers_GPM *this) {
printf("GPM: Polling %s...\n", this->path);
}
Hardware_MouseDriver Hardware_MouseDrivers_GPM_Methods = {
.open = Hardware_MouseDrivers_GPM_Open,
.close = Hardware_MouseDrivers_GPM_Close,
.poll = Hardware_MouseDrivers_GPM_Poll
};
/* DevInput */
typedef struct _Hardware_MouseDrivers_DevInput {
char *path;
} Hardware_MouseDrivers_DevInput;
static int Hardware_MouseDrivers_DevInput_Open(Hardware_MouseDrivers_DevInput *this, char *path);
static int Hardware_MouseDrivers_DevInput_Close(Hardware_MouseDrivers_DevInput *this);
static int Hardware_MouseDrivers_DevInput_Poll(Hardware_MouseDrivers_DevInput *this);
static int Hardware_MouseDrivers_DevInput_Open(Hardware_MouseDrivers_DevInput *this, char *path) {
printf("DevInput: Opening %s...\n", path);
this->path = path;
}
static int Hardware_MouseDrivers_DevInput_Close(Hardware_MouseDrivers_DevInput *this) {
printf("DevInput: Closing %s...\n", this->path);
}
static int Hardware_MouseDrivers_DevInput_Poll(Hardware_MouseDrivers_DevInput *this) {
printf("DevInput: Polling %s...\n", this->path);
}
Hardware_MouseDriver Hardware_MouseDrivers_DevInput_Methods = {
.open = Hardware_MouseDrivers_DevInput_Open,
.close = Hardware_MouseDrivers_DevInput_Close,
.poll = Hardware_MouseDrivers_DevInput_Poll
};
/* Test drivers */
void TestDriver(Hardware_MouseDriver driver, void *data) {
/* Access the driver using a generic interface
* (Hardware_MouseDriver) */
driver.poll(data);
}
void main() {
Hardware_MouseDrivers_GPM gpm;
Hardware_MouseDrivers_DevInput devinput;
Hardware_MouseDrivers_GPM_Open(&gpm, "/dev/gpmctl");
Hardware_MouseDrivers_DevInput_Open(&devinput, "/dev/input/mice");
TestDriver(Hardware_MouseDrivers_GPM_Methods, &gpm);
TestDriver(Hardware_MouseDrivers_DevInput_Methods, &devinput);
Hardware_MouseDrivers_GPM_Close(&gpm);
Hardware_MouseDrivers_DevInput_Close(&devinput);
}