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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T08:36:39+00:00 2026-05-18T08:36:39+00:00

So i thought this would be straight forward but i keep getting compile errors,

  • 0

So i thought this would be straight forward but i keep getting compile errors, which probably means i am doing something stupid.

So i am using C and i want to save a pointer to a function in a global variable.

As a test case i have three files. Test.c, Test.h and FunctionPtr.c

Test.h goes like this

void (*MyCallBack)(void);

int SetFunc( void (*CallBackArg)(void));
void CallFunc();

Test.c Goes like this

#include <stdio.h>
#include <stdlib.h>
#include "test.h"
void SetFunc( void (*CallBackArg)(void)){

    printf("Set CallBack\n");
    MyCallBack=CallBackArg;
}

void CallFunc(){
    printf("In Call Func\n");
    MyCallBack();
}

and FunctionTest.c goes like this

#include <stdio.h>
#include <stdlib.h>
#include "test.h"


void MyFunc(){
    printf("Work!\n");
}
int main()
{
    SetFunc(MyFunc);
    CallFunc();

}

When i compile using gcc FunctionTest.c test.c test.h -o FunctionTest

I get the following error…

test.c:4: error: conflicting types for ‘SetFunc’
test.h:4: note: previous declaration of ‘SetFunc’ was here

I cant figure out what i am doing wrong? Perhaps i am not declaring the Global Pointer right?

  • 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-18T08:36:39+00:00Added an answer on May 18, 2026 at 8:36 am
    int SetFunc( void (*CallBackArg)(void));
    
    void SetFunc( void (*CallBackArg)(void))
    

    The return types are different, that’s your problem. You have to declare it the same way in the header as in the .c file.

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

Sidebar

Related Questions

I could probably find this out from somewhere else but thought it would be
I thought this would be simple, but its not working .. in both the
I would have thought this would be an easy one to Google, but I've
I thought this code would work, but the regular expression doesn't ever match the
This discussion started over here but I thought it would be nice to have
I thought this would have done it... $rowfetch = $DBS->{Row}->GetCharValue(meetdays); $rowfetch = /[-]/gi; printline($rowfetch);
I thought I'd offer this softball to whomever would like to hit it out
Just listening to this week's podcast and thought it would be nice to group
While I'm googling/reading for this answer I thought I would also ask here. I
Thanks for reading this. I would have thought it would be as simple as

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.