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

  • Home
  • SEARCH
  • 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 8613863
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T04:59:00+00:00 2026-06-12T04:59:00+00:00

I have 4 files: main.c #include <stdio.h> #include <string.h> #include <stdlib.h> #include main.h int

  • 0

I have 4 files:

main.c

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "main.h"


int main() {
    struct Fun *fun = (struct Fun*)malloc(sizeof(struct Fun));
    fun->a = 2;
    fun->b = 12;
    fun->Func = Plus();
    int result = fun->Func(fun, 8);
    printf("%d\n", result);
    return 0; }

main.h

    #ifndef MAN_H_
    #define MAN_H_

    struct Fun {
        int   a;
        int   b;
        int (*Func)(struct Fun *x,int y);

    };

header.c

    #include "header.h"

    int Plus(struct Fun *x, int y) {
        return x->a * x->b + y; };

header.h

    #ifndef HEADER_H_
    #define HEADER_H_

    #include "man.h"

    #endif /* HEADER_H_ */

when I build, I get a warning:

../main.c:12:5: warning: implicit declaration of function ‘Plus’ [-Wimplicit-function-declaration]
../main.c:12:15: warning: assignment makes pointer from integer without a cast [enabled by default]

if I run, it has no result.

But when I put all the code to main.c and edit fun->Func = Plus(); to fun->Func = Plus; it works fine: no warning, and the result is 32.

  • 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-12T04:59:01+00:00Added an answer on June 12, 2026 at 4:59 am

    You should provide a function signature for Plus in header.h, and also add an #include "header.h" in main.c, so that something is known about the Plus function when it’s used in main.c.

    In header.h:

    int Plus(struct Fun *, int);
    

    Without such a signature, when compiling main.c the compiler makes assumptions about the function: an implicit declaration. This implicit declaration won’t match the actual function definition.

    Also, changing fun->Func = Plus(); to fun->Func = Plus; is still necessary: the first form assigns to your function pointer the result of an attempted function call, the second form is the correct way to assign a function pointer.

    Finally, this is likely just a cut/paste omission, but main.h is missing an #endif.

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

Sidebar

Related Questions

I have three files, a main .cpp file: #include <stdio.h> #include myClass.h int main()
I have issues with the following code: #include <stdio.h> #include <stdlib.h> #include <string.h> #include
I have an PHP/HTML main page, in which I include different other PHP files
I have 4 files: shared.h main.cpp something.h something.cpp shared.h: #ifndef SHARED_H #define SHARED_H int*
I have 3 files main.cpp a.h b.h main.cpp includes both a.h and b.h b.h
I have a sitewide include file that I include in pages in the main
I have the files main.c , version1.c , version2.c and header.h version1.c and version2.c
I have a project in which i have the following files main.wxs - directory
I have a two JavaScript files: Main.js Pmt.js I'm also using thick box (Ajax
I have two frames in different files (main frame and settings frame), and I'd

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.