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 8953451
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T14:05:51+00:00 2026-06-15T14:05:51+00:00

I have a struct with two pointers to functions and some data. The functions

  • 0

I have a struct with two pointers to functions and some data. The functions are definition-wise the same, however they should perform different tasks (which is why they have different names in the original source). If I use the first function, all goes well, but if I use the second functions, I get a segfault – even if I pass the same pointer to both functions.

The pointers are neither NULL nor garbage, or else both would fail – but somehow only the latter gets segfaulted. Why is that?

I have the following code:

typedef void (*funcOneDef)(void*);
typedef void (*funcTwoDef)(void*);
typedef struct structImpl* structPt;

struct structImpl {
    void *data;
    funcOneDef funcOne;
    funcTwoDef funcTwo;
}; 

structPt create(void *data, funcOneDef funcOne, funcTwoDef funcTwo)
{
    structPt test = malloc(sizeof(test));
    test->data = data;
    test->funcOne = funcOne;
    test->funcTwo = funcTwo;
    return test;
}

void execFuncOne(structPt test) 
{
    test->funcOne(test->data); //works!
}

void execFuncTwo(structPt test)
{
    test->funcTwo(test->data); //segfault!
}

PS: No need to test this, because somehow this works, but my original source – which is basically the same – doesn’t?

  • 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-06-15T14:05:53+00:00Added an answer on June 15, 2026 at 2:05 pm

    Shouldn’t the line structPt test = malloc(sizeof(test)); be structPt test = malloc(sizeof(structImpl));?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two mdi applications, both of which retrieve their data from the same
I have an array of structs. The struct has two function pointers. Each element
I have two objects both of the same type, for instance: typedef struct s_Object
Hey I have a problem comparing the value of a CGPoint (struct with two
So, I have two structs: struct coordinate { float x; float y; } struct
I have a problem. There are two classes: struct Base { Base* retain() {
I have two window form applications written in C, one holds a struct consisting
I have two questions related to function objects and function pointers, Question : 1
I have a simple question in understanding the pointers and struct definitions in the
I have two functions: void free_this(THIS *this) { THIS *this_tmp; while (this_tmp = this)

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.