Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 454029
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T22:13:48+00:00 2026-05-12T22:13:48+00:00

Is there a compiler directive in order to ignore the initialization from incompatible pointer

  • 0

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);
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T22:13:49+00:00Added an answer on May 12, 2026 at 10:13 pm

    Cast the assignments to the proper types (function pointers with void * rather than your instance pointer):

     .open= (int (*)(void*, char *))Hardware_MouseDrivers_GPM_Open;
    

    Or make a type and use it in the definition and initialization of the struct:

    typedef int (*openfcnt_t)(void*, char *);
    
    typedef struct _Hardware_MouseDriver {
            openfnct_t open;
    } Hardware_MouseDriver;
    

    and then

     .open= (openfnct_t)Hardware_MouseDrivers_GPM_Open;
    

    EDIT:

    Upon further thought the easiest and least fiddly way for a C program will be:

     .open= (void *)Hardware_MouseDrivers_GPM_Open;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 211k
  • Answers 211k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer http://www.google.nl/#hl=nl&source=hp&q=jquery+menus&btnG=Google+zoeken&meta=&aq=f&oq=jquery+menus&fp=9f25ce630386be7c http://www.google.nl/#hl=nl&q=jquery+menus+wordpress&meta=&aq=f&oq=&fp=9f25ce630386be7c And after 2 mins of codebrowsing you should… May 12, 2026 at 10:14 pm
  • Editorial Team
    Editorial Team added an answer No. Since you do not know the type that the… May 12, 2026 at 10:14 pm
  • Editorial Team
    Editorial Team added an answer ShowInTaskBar EDIT : If you are hiding the form when… May 12, 2026 at 10:14 pm

Related Questions

I have a templating system that looks similar to old-style ASP code. I run
I tried to assign a very small number to a double value, like so:
I've got a bunch of legacy code that I need to write unit tests
I wish to know is there a compiler directive which I can use in
Is there a way in Delphi 2009 to have a section of code conditionally

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.