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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T11:05:57+00:00 2026-06-10T11:05:57+00:00

I understand that the config.h header file should be considered to be an internal

  • 0

I understand that the config.h header file should be considered to be an internal header file. Now I wonder how to publish something that depends on config.h settings without publishing the config.h itself.

Say, I have a public function returning bool, i.e. depending on either stdbool.h or any appropriate definition of bool. It should be declared within a public header, but this header may be used in an environment without stdbool.h and maybe even without config.h or with a config.h saying nothing about the presence of bool.

I came up with an unsatisfactory solution like this:

#if HAVE_STDBOOL_H || !HAVE_CONFIG_H
# include <stdbool.h>
#endif
#if !__bool_true_false_are_defined
# if !HAVE__BOOL
  typedef int _Bool;
# endif
  typedef _Bool bool;
# define true (bool)1
# define false (bool)0
#endif

extern bool public_bool(void);

This should work in most standard cases but may fail in many others.

Maybe it’s obsolete taking environments without stdbool.h into consideration at all today (I don’t know), but this is just a sample of my comprehension gap concerning the autotool-thing. What is the best practice to deal with the problem in general?

  • 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-10T11:05:57+00:00Added an answer on June 10, 2026 at 11:05 am

    In the specific case of <stdbool.h>, we chose to avoid depending on config.h and to rely on the C (or C++) compiler to tell us what is OK. The code includes this header, and this header sorts out the mess. It is known to work on Mac OS X, Linux, Solaris, HP-UX, AIX, Windows. The actual header file name is not ourbool.h, but I’ve mangled its header guards and comments so it looks as if that is what it is called. The comments quote the C99 standard for the licence to perform as it does. Note that it also works correctly if <stdbool.h> has already been included, and it works correctly if <stdbool.h> is included after it has been included (and getting this correct was not 100% pain-free). Defining __bool_true_false_are_defined is crucial to this inter-working. (When your code is in use by other people, you can’t mandate that they do not use <stdbool.h> themselves, either before or after your header is included.)

    #ifndef OURBOOL_H_INCLUDED
    #define OURBOOL_H_INCLUDED
    
    /*
    ** Ensure that type bool with constants false = 0 and true = 1 are defined.
    ** C++ (ISO/IEC 14882:1998/2003/2011) has bool, true and false intrinsically.
    ** C (ISO/IEC 9899:1999) has bool, true and false by including <stdbool.h>
    ** C99 <stdbool.h> also defines __bool_true_false_are_defined when included
    ** MacOS X <dlfcn.h> manages to include <stdbool.h> when compiling without
    ** -std=c89 or -std=c99 or -std=gnu89 or -std=gnu99 (and __STDC_VERSION__
    ** is not then 199901L or later), so check the test macro before defining
    ** bool, true, false.  Tested on MacOS X Lion (10.7.1) and Leopard (10.5.2)
    ** with both:
    **      #include "ourbool.h"
    **      #include <stdbool.h>
    ** and:
    **      #include <stdbool.h>
    **      #include "ourbool.h"
    **
    ** C99 (ISO/IEC 9899:1999) says:
    **
    ** 7.16 Boolean type and values <stdbool.h>
    ** 1 The header <stdbool.h> defines four macros.
    ** 2 The macro
    **       bool
    **   expands to _Bool.
    ** 3 The remaining three macros are suitable for use in #if preprocessing
    **   directives.  They are
    **       true
    **   which expands to the integer constant 1,
    **       false
    **   which expands to the integer constant 0, and
    **       __bool_true_false_are_defined
    **   which expands to the integer constant 1.
    ** 4 Notwithstanding the provisions of 7.1.3, a program may undefine and
    **   perhaps then redefine the macros bool, true, and false.213)
    **
    ** 213) See 'future library directions' (7.26.7).
    **
    ** 7.26.7 Boolean type and values <stdbool.h>
    ** 1 The ability to undefine and perhaps then redefine the macros bool, true,
    **   and false is an obsolescent feature.
    **
    ** Use 'unsigned char' instead of _Bool because the compiler does not claim
    ** to support _Bool.  This takes advantage of the license of paragraph 4.
    */
    
    #if !defined(__cplusplus)
    
    #if __STDC_VERSION__ >= 199901L
    #include <stdbool.h>
    #elif !defined(__bool_true_false_are_defined)
    #undef bool
    #undef false
    #undef true
    #define bool    unsigned char
    #define false   0
    #define true    1
    #define __bool_true_false_are_defined 1
    #endif
    
    #endif /* !_cplusplus */
    
    #endif /* OURBOOL_H_INCLUDED */
    

    Clearly, if you want to allow for the possibility of HAVE_STDBOOL_H, you may, but it is not needed. You can also decide what to do if HAVE_CONFIG_H is defined, but again it is not needed.

    To use this, your header would contain:

    #ifndef YOURHEADER_H_INCLUDED
    #define YOURHEADER_H_INCLUDED
    ...other #includes as needed...
    #include "ourbool.h"      /* Or #include "project/ourbool.h" */
    ...other material...
    
    extern bool boolean_and(bool lhs, bool rhs);
    
    ...other material...
    #endif /* YOURHEADER_H_INCLUDED */
    

    The precise location of ourbool.h in yourheader.h is not critical as long as it is before you declare types, functions or (perish the thought) variables that use the bool type.

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

Sidebar

Related Questions

In WCF services and a variety of other .NET apps, I understand that app.config
I'm a noob; please help me understand this authentication config / bindings stuff that
I understand that storage history is something that is better to keep for vcs
I now understand that the following code will not work because I'm assigning window.onload
I have a config file that the user can specify sections, and then within
So I have a yaml file that I'm using as a config file. I'm
I have a config file in my project that includes some info that is
Now that i've been doing some research I understand that I need to be
I understand that in Grails by default configuration vars are stored in Config.groovy and
I understand that: '\n' // literally the backslash character followed by the character for

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.