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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T01:20:27+00:00 2026-06-05T01:20:27+00:00

Is it ever useful to include a header file more than once in C

  • 0

Is it ever useful to include a header file more than once in C or C++?

If the mechanism is never used, why would the compiler ever worry about including a file twice; if it really were useless, wouldn’t it be more convenient if newer compilers made sure every header is included only once?

Edit:

I understand that there are standard ways of doing things like include guards and pragma once, but why should you have to specify even that? Shouldn’t it be the default behavior of the compiler to include files only once?

  • 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-05T01:20:29+00:00Added an answer on June 5, 2026 at 1:20 am

    Yes, it’s useful when generating code with the preprocessor, or doing tricks like Boost.PP does.

    For an example, see X Macros. The basic idea is that the file contains the body of the macro and you #define the arguments and then #include it. Here’s a contrived example:

    macro.xpp

    std::cout << MESSAGE;
    #undef MESSAGE
    

    file.cpp:

    int main() {
    # define MESSAGE "hello world"
    # include "macro.xpp"
    }
    

    This also allows you to use #if and friends on the arguments, something that normal macros can’t do.

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

Sidebar

Related Questions

Wondering if it would ever be useful to index every possible state of an
Ever since deleting the original settings.settings file I have had endless problems getting the
Ever since I started programming this has been something I have been curious about.
Would Devise still be useful if I'm using sign on with google? that is,
A coworker and i were debating today whether or not it is ever useful
Have you ever used an XHR object to intercept onreadystatechange with a readyState different
When ever I access my ashx eg download.ashx?id=18 it gets the file, but then
Classic database table design would include an tableId int index(1,1) not null which results
Cedrick Collomb's Unlocker is one of the most useful utilities I've ever come across
Every program written in C that I've ever seen #include s <stdlib.h> , at

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.