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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T10:41:27+00:00 2026-05-30T10:41:27+00:00

The question seems to be a classic one, but I didn’t find an answer:

  • 0

The question seems to be a classic one, but I didn’t find an answer:

I have two struct type written in C —— struct type A and struct type B, and B use A while A use B at the same time.

In a.h:

#include "b.h"
struct B;
typedef struct A {
    void (*func)(struct B* b);
}A;

In b.h:

#include "a.h"
typedef struct B {
    A a;
}B;

though this will work, it has a consequence — when using the function fun “func”, if I pass a variable declared in the form:

B* someb;

not:

struct B* someb;

there will be a warning when compiling, saying incompatible pointer type. Is this normal? could I avoid this warning?

  • 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-30T10:41:29+00:00Added an answer on May 30, 2026 at 10:41 am

    From your a.h header file, simply remove the line #include "b.h". The forward declaration struct B; is all you need.

    That change will fix the circular include dependency, and will make any code using these headers more sane.

    Then, wherever you want to make use of the B struct, simply include b.h, and use it with or without the struct keyword.

    Some code to illustrate : the a.h header file :

    /* a.h */
    struct B;
    
    typedef struct A {
        void (*func)(struct B* b);
    } A;
    

    The b.h header file :

    /* b.h */
    #include "a.h"
    
    typedef struct B {
        A a;
    } B;
    

    A file that uses these header files :

    /* some_file.c */
    #include "b.h"
    
    void fun() {
        B someb;
        someb.a.func(&someb);
    }
    
    void fun2() {
        struct B someb;
        someb.a.func(&someb);
    }
    

    Both fun and fun2 are just fine (from the compiler point of view – func hasn’t been initialized, so calling it will cause an issue at run time).

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

Sidebar

Related Questions

This question seems to have been asked a lot, but I haven't seen an
This is a classic sort of question, I suppose, but it seems that most
From another question I recently posted, it seems that Classic ASP might not be
This question seems to be asked freqeuently over the internet but I still can't
The question seems pretty well formulated I have a virtual machine which implements only
Sorry if this question seems stupid, but it's stumped me for a couple days,
Sorry if this question seems a bit complex but I think its all related
I have a set of web services written in classic asp. I want to
the question seems clear enough, but I'll add a case using (var context =
This question seems silly. But I'm new to javascript and sencha touch. Can I

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.