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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T10:18:02+00:00 2026-05-13T10:18:02+00:00

I roughly understand the rules with what #include does with the C preprocessor, but

  • 0

I roughly understand the rules with what #include does with the C preprocessor, but I don’t understand it completely. Right now, I have two header files, Move.h and Board.h that both typedef their respective type (Move and Board). In both header files, I need to reference the type defined in the other header file.

Right now I have #include “Move.h” in Board.h and #include “Board.h” in Move.h. When I compile though, gcc flips out and gives me a long (what looks like infinite recursive) error message flipping between Move.h and Board.h.

How do I include these files so that I’m not recursively including indefinitely?

  • 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-13T10:18:02+00:00Added an answer on May 13, 2026 at 10:18 am

    You need to look into forward declarations, you have created an infinite loops of includes, forward declarations are the proper solution.

    Here’s an example:

    Move.h

    #ifndef MOVE_H_
    #define MOVE_H_
    
    struct board; /* forward declaration */
    struct move {
        struct board *m_board; /* note it's a pointer so the compiler doesn't 
                                * need the full definition of struct board yet... 
                                * make sure you set it to something!*/
    };
    #endif
    

    Board.h

    #ifndef BOARD_H_
    #define BOARD_H_
    
    #include "Move.h"
    struct board {
        struct move m_move; /* one of the two can be a full definition */
    };
    #endif
    

    main.c

    #include "Board.h"
    int main() { ... }
    

    Note: whenever you create a “Board”, you will need to do something like this (there are a few ways, here’s an example):

    struct board *b = malloc(sizeof(struct board));
    b->m_move.m_board = b; /* make the move's board point 
                            * to the board it's associated with */
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 287k
  • Answers 287k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer I'm under the impression that you're trying to involve MonadError… May 13, 2026 at 5:10 pm
  • Editorial Team
    Editorial Team added an answer Short answer: I'm afraid there isn't much you could easily… May 13, 2026 at 5:10 pm
  • Editorial Team
    Editorial Team added an answer What version of out are you using ? older version… May 13, 2026 at 5:10 pm

Related Questions

The template method pattern and the strategy pattern do roughly the same thing. I
I'm troubleshooting an OutOfMemory exception in my .NET 2.0 Windows Service application. To understand
There is a custom implementation of KSPA which needs to be re-written. The current
How exactly does NSInvocation work? Is there a good introduction? I’m specifically having issues
Problem: my mod_perl leaks and I cannot control it. I run mod_perl script under

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.