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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T01:34:39+00:00 2026-05-20T01:34:39+00:00

This question is one of several that discuss naming conventions for C++ include guards.

  • 0

This question is one of several that discuss naming conventions for C++ include guards. The person asking that question thinks that this naming convention:

#ifndef FOO_H
#define FOO_H

// ...

#endif

is a bit non-intuitive when taken by itself (what does FOO_H mean?) and I tend to agree.

Others say that, barring the need to add more stuff for better collision avoidance (like PROJECTNAME_FOO_H_SDFFGH69876GF), the name FOO_H is just fine because it’s clear from its context what its purpose is (namely, it’s at the beginning of the files of the same name and it’s clear that it’s an include guard).

I could buy this if the only purpose of having FOO_H would be to guard against multiple inclusion, but are there conditions for which I’d want to have FOO_H elsewhere in the files? I’d think conditional compilation would be a good reason, in which case naming it something like FOO_H_INCLUDED would be clearer.

Are there straightfoward uses akin to this, or should I avoid repurposing the include guards?

  • 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-20T01:34:40+00:00Added an answer on May 20, 2026 at 1:34 am

    I think the question is flawed in itself. The term include guards refers to #defines and checks for #defined in the particular use of guarding against multiple inclusion, which is as much to say that is the only use for that.

    Now taken a little more generally, defines and conditional compilation can be used for other things, like writing bits of code that are platform dependent and will only get compiled under some circumstances…

    Whether FOO_H or FOO_H_INCLUDED is better, I will always say that the later is the most expressive, and then I will go back to vi and type FOO_H in my next foo.h header. Again, as I mentioned in a comment on the other question, you grow used to the pattern:

    #ifndef XXXXXXXXX
    #define XXXXXXXXX
    
    #endif
    

    as the first two and last line in a file and you end noticing. That is until it bites back if you have reused the same name…

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

Sidebar

Related Questions

The current top-voted to this question states: Another one that's not so much a
After posting this question and reading that one I realized that it is very
I can see that this question has been asked several times, but none of
So I got this question from one of the developers in my team: What
This question is related to this one , though I think I was a
This question is a follow up on one of my other questions, Can I
This question has spawned out of this one. Working with lists of structs in
[This question is related to but not the same as this one .] My
[This question is related to but not the same as this one .] If
I hope this question is not a RTFM one. I am trying to write

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.