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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T20:28:21+00:00 2026-05-26T20:28:21+00:00

I use a global config.h in my project to define various flags that enable/disable

  • 0

I use a global “config.h” in my project to define various flags that enable/disable features. I defined using the convention:

#define ENABLE_FEATURE1    0 // feature is disabled
#define ENABLE_FEATURE2    1 // feature is enabled

And later in the source files I test for them:

#if ENABLE_FEATURE1
  // do something
#endif
#if ENABLE_FEATURE2
  // do something
#endif

However, it has happened a few times that I forgot to include “config.h” in a cpp file that tests for those flags. Then I get no error or warning from the preprocessor, and the program builds fine, but the compiler treats all the undefined flags as if they’re set to zero, so the feature is treated as disabled in that cpp file, while it’s treated as enabled in the rest of the source files.

Sometimes the consequences have not been immediately obvious even at runtime.

  • 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-26T20:28:22+00:00Added an answer on May 26, 2026 at 8:28 pm

    Insert the following #if in source files.

    #if !defined(ENABLE_FEATURE1) && !defined(ENABLE_FEATURE2)
    #error "Please include <config.h>"
    #endif
    

    Then, you may have another problem: what if I forgot to insert the above #ifdef? 🙂

    In this case, you may include config.h in a precompiled header (e.g., stdafx.h) and turn on using precompiled header. If a file doesn’t include stdafx.h, MSVC will raise an error.

    Finally, you may write a simple script to check whether every source code has config.h.

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

Sidebar

Related Questions

I have set an array in my config file that I use global in
Global scope allows you to use a variable in a function that was defined
Somebody said that when your PHP code and application use global variables then it
Note: while the use-case described is about using submodules within a project, the same
I use config module to store variables global to all modules. Is it a
I use global variable $table_prefix to differ whether I work on Word Press or
Due to a wave of criticism to use Global Vars in my Java post
As I know, I can use global variable transfer the value among the multi
Do you use a global, catchall namespace for all of your extension methods, or
Is it a problem if you use the global keyword on variables you don't

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.