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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T06:01:57+00:00 2026-06-07T06:01:57+00:00

I have a situation where two of my header files require the data structures

  • 0

I have a situation where two of my header files require the data structures defined in either one, i.e. no matter which order you include them it won’t compile

however, one of the problem data structures only contains pointers to the data structure declared in the other header file so I would have though that technically it doesn’t need to know at this point how big the data structure is so it shouldn’t be complaining

A simplified example of what I mean is outlined below. I would have thought that the array of modes in Library doesn’t need to know how big a Mode is, only how big a pointer to a Mode is therefore the compiler shouldn’t complain if it hasn’t yet seen the declaration of Mode in the other header file.

header_1.h

typedef struct
{
    Mode **modes; 
} Library;

header_2.h

typedef struct
{
    int number;
    char *name;
} Mode;
  • 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-07T06:01:58+00:00Added an answer on June 7, 2026 at 6:01 am

    As currently written, your example does not show the mutual cross-referencing that you mention in the question.

    The compiler must be told something about each type it uses. You could use in header_1.h just:

    typedef struct Mode Mode;
    
    typedef struct
    {
        Mode **modes; 
    } Library;
    

    That would make it compile, at least. The compiler doesn’t need the details, but it does need to know that Modes is a type.

    Edit:
    Note that header_2.h should be modified for this to work. You have to ensure that each typedef appears just once. After you have the typedefs in place, you specify the structure content (definition) once, and you omit the keyword typedef and the typedef name from the structure definition. And you have to decide on exactly the cross-references will be managed. For example, should header_1.h include header_2.h anyway.

    I don’t remember encountering a case where I really needed mutually referencing structures (in quite a long time programming — long enough that I could have forgotten a example). I do now remember a case of structures mutually referencing each other; it was in a version of make originally written for Minix. I still regard such a requirement as somewhat ‘pathological’ (or, if you prefer, as a ‘code smell’) and as something to be avoided whenever possible. If you really must manage it, then the section below explains how I’d go about doing it (and more or less how the make program did go about it).

    Mutually-referencing structures

    If you truly have two mutually referencing structures, you should (re)consider why you think two headers are better than one. If you still need two headers, you use an idiom like:

    header_1.h

    #ifndef HEADER_1_H_INCLUDED
    #define HEADER_1_H_INCLUDED
    
    #ifndef TYPEDEF_MODE
    #define TYPEDEF_MODE
    typedef struct Mode Mode;
    #endif
    #ifndef TYPEDEF_LIBRARY
    #define TYPEDEF_LIBRARY
    typedef struct Library Library;
    #endif
    
    struct Library
    {
        ...
        Mode    **modes;
        ...
    };
    
    #endif /* HEADER_1_H_INCLUDED */
    

    header_2.h

    #ifndef HEADER_2_H_INCLUDED
    #define HEADER_2_H_INCLUDED
    
    #ifndef TYPEDEF_MODE
    #define TYPEDEF_MODE
    typedef struct Mode Mode;
    #endif
    #ifndef TYPEDEF_LIBRARY
    #define TYPEDEF_LIBRARY
    typedef struct Library Library;
    #endif
    
    struct Mode
    {
        ...
        Library    **liblist;
        ...
    };
    
    #endif /* HEADER_2_H_INCLUDED */
    

    The repeated typedef ‘detection’ code is not nice; a single header is better, in my estimation. However, you can include header_1.h and header_2.h above in either order and it should compile.

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

Sidebar

Related Questions

I have this situation (two classes with two different header files): b.h #include a.h
Consider the following situation: We have two Localizable.string files, one in en.lproj and one
I have a class (A) which has to include two files, class X and
In this situation I have two models, Comment and Score. The relationship is defined
this is my situation: I have two org.w3c.dom.Document created from two xml files. What
I have a bizarre situation with two bzr branches. The two branches differ one
I have the following situation: I have two threads thread1 , which is a
I have a situation where I have two arrays and I use one array(A)
I have a situation where two separate companies wish to 'join' their iOS apps
I have a situation where two objects of the same type have parents of

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.