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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T11:16:07+00:00 2026-06-04T11:16:07+00:00

I was hoping somebody could explain why #include <stdbool.h> printf(size of bool %d\n, sizeof(bool));

  • 0

I was hoping somebody could explain why

#include <stdbool.h>

printf("size of bool %d\n", sizeof(bool));
printf("size of int %d\n", sizeof(int));

outputs to

size of bool 1
size of int 4

I’ve looked at http://pubs.opengroup.org/onlinepubs/009695399/basedefs/stdbool.h.html which seems to indicate that bool is essentially a macro for _Bool which, when set to true or false, is really just a macro for an integer constant. If it is an integer, why is it not the same size?

I’m asking because it took us far too long to debug a program for which we did not allocate enough memory.

  • 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-04T11:16:09+00:00Added an answer on June 4, 2026 at 11:16 am

    The _Bool type in C99 (typedef‘ed to bool in stdbool.h) doesn’t have a standard defined size, but according to section 6.2.5 of the C99 Standard:

    2 An object declared as type _Bool is large enough to store the values 0 and 1.
    

    In C, the smallest addressable object (aside from bitfields) is the char, which is at least 8-bits wide, and sizeof(char) is always 1.

    _Bool and bool therefore have a sizeof of at least 1, and in most implementations that I’ve seen, sizeof(bool) / sizeof(_Bool) is 1.

    If you take a look at GCC’s stdbool.h, you’ll get this:

     #define bool    _Bool
     #if __STDC_VERSION__ < 199901L && __GNUC__ < 3
     typedef int _Bool;
     #endif
    
     #define false   0
     #define true    1
    

    So if using an older version of GCC and an old version of the C standard when compiling, you will use int as a _Bool type.

    Of course, as an interesting thing, check this out:

    #include <stdio.h>
    #include <stdbool.h>
    
    int main() {
       printf("%zu\n", sizeof(_Bool));
       printf("%zu\n", sizeof(true));
       printf("%zu\n", sizeof(false));
    
    }
    

    Output:

    λ > ./a.out 
    1
    4
    4
    

    GCC 4.2.4, Clang 3.0, and GCC 4.7.0 all output the same. As trinithis points out, sizeof(true) and sizeof(false) produce larger sizes because they are taking the size of an int literal, which is at least sizeof(int).

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

Sidebar

Related Questions

I was hoping somebody could help me with with this. I am trying to
I have a sorting/grouping issue that I'm hoping somebody could add some insight on.
I have a small issue I was hoping somebody could help me with. I
Here's some more weird macro behavior I was hoping somebody could shed light on:
I'm working on an assignment involving Racket and I was hoping somebody could lead
Having little experience in Opengl es (or opengl) I was hoping somebody could help
I'm sure there isn't but I was hoping somebody could help me to work
I was hoping somebody might be able to give me a hand by pointing
O.K I'm really confused about some resizing behaviour in flex and I'm hoping somebody
I'm hoping somebody might be able to shed some light on this. We have

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.