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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T04:54:10+00:00 2026-06-12T04:54:10+00:00

I have code for bool typedef typedef enum bool { false, true, } bool;

  • 0

I have code for bool typedef

typedef enum bool {
    false,
    true,
} bool;

in two headers files if it is not included in the ultimate parent header file, child C files cannot, of course, use type bool, though children of the lesser header file that also defines it can.

However if I define it in the ultimate parent header file then the lesser header file definition errors with “bool has already been declared in the current scope”

I need a solution for the lesser header where it may be included on a project that may or may not have already defined bool… What is the best way to do this??

Ta

  • 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-12T04:54:11+00:00Added an answer on June 12, 2026 at 4:54 am

    First of all, if you’re working with a C99 compiler or later, there’s already a standard Boolean type defined in stdbool.h.

    Secondly, you can usually avoid testing against true and false values directly, and I’ve found over the years that this actually leads to code that’s a little easier to read and less error-prone (that’s just a personal opinion, though — YMMV).

    The immediate solution is to surround your typedefs with an include guard:

    #ifndef BOOL_DEFINED
    #define BOOL_DEFINED
    typedef enum bool {
      false,
      true
    } bool;
    #endif
    

    This will keep the type from being declared more than once. However, as you’ve discovered, putting the same type definition in two different headers is a recipe for heartburn. It would be better to put the definition in its own header file (with the include guards as shown above), and then include that file where necessary.

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

Sidebar

Related Questions

Lets say we have this code: bool KeepGoing = true; DataInThread = new Thread(new
I have the following code: var bool:String = true; Without an if block or
I have the following block code typedef BOOL(^FieldValidationBlock)(NSString *); FieldValidationBlock aBlock = ^(NSString *input){
Lets say in a file I have some code in two files part of
If I have some code that looks something like: typedef struct { bool some_flag;
I have the following code: typedef boost::variant<LandSearchParameter, WaterSearchParameter> SearchParameter; enum Visibility{ CLEAR, CLOUDY, FOG,
I have this code typedef struct { const char* fooString; const bool fooBool; }fooStruct;
I have a vector code in c++ this: typedef vector<boost::tuple<ppa::Node*, ppa::Node*, ppa::Node*, bool> >::iterator
I have a double type bool so have added to a header: typedef double
I have following code: typedef enum { FOO, BAR, BAZ } foo_t; static void

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.