{"id":7739,"date":"2026-08-29T00:01:26","date_gmt":"2026-08-29T07:01:26","guid":{"rendered":"https:\/\/c-for-dummies.com\/blog\/?p=7739"},"modified":"2026-08-22T14:34:05","modified_gmt":"2026-08-22T21:34:05","slug":"booleans","status":"publish","type":"post","link":"https:\/\/c-for-dummies.com\/blog\/?p=7739","title":{"rendered":"Booleans"},"content":{"rendered":"<p>One of the weaknesses of the C language when measured against the newer, trendier programming languages is that it lacks a Boolean type. That is, a variable that&#8217;s either one or zero. This issue was addressed with the C99 standard and its addition of the underscore <a href=\"https:\/\/c-for-dummies.com\/blog\/?p=2953\"><em>_Bool<\/em> data type<\/a>. It&#8217;s furthered in the C23 standard with the (better) <em>bool<\/em> type as well as the <em>true<\/em> and <em>false<\/em> keywords available in just about every other programming language used today. It&#8217;s time for a deep dive into the binary pool of bool.<br \/>\n<!--more--><br \/>\nYes, I know that the C99 standard was sincere with its addition of the underscore keywords: <em>_Bool<\/em>, <em>_Complex<\/em>, and <em>_Imaginary<\/em>. Adding the initial underscore seems like an insult to me. Requiring the initial capital letter adds injury to the insult. Further: <em>_Bool<\/em> is deprecated with the C23 standard. So much for that.<\/p>\n<p>Despite the apparent desperation, the <code>stdbool.h<\/code> header file is available. This resource is what C programmers lean on when they desire to fill the void left in C by missing binary\/Boolean capabilities. It&#8217;s such a useful header file, that many coders add it along with <code>stdio.h<\/code> and <code>stdlib.h<\/code> by default.<\/p>\n<p>The <em>stdbool.h<\/em> header carries three burdens:<\/p>\n<ul>\n<li> It defines <em>bool<\/em> as a data type<\/li>\n<li> It defines the <em>true<\/em> constant<\/li>\n<li> It defines the <em>false<\/em> constant<\/li>\n<\/ul>\n<p>The header file also contains a defined constant <em>_bool_true_false_are_defined<\/em>, which is set to 1. This constant is used as a test to ensure that the header file is included and that your code can use <em>bool<\/em>, <em>true<\/em>, and <em>false<\/em> without messing up anything. I don&#8217;t know how a C23 compiler deals with this header file as it has its own keywords for <em>bool<\/em>, <em>true<\/em>, and <em>false<\/em>.<\/p>\n<p>In the <code>stdbool.h<\/code> header file, the <em>bool<\/em> data type is tied to <em>_Bool<\/em>. It&#8217;s defined, not <em>typedef<\/em>&#8216;d:<\/p>\n<p><code>#define bool _Bool<\/code><\/p>\n<p>Here are the definitions for <em>true<\/em> and <em>false<\/em>:<\/p>\n<p><code>#define true 1<br \/>\n#define false 0<\/code><\/p>\n<p>Since I first learned C, my habit was to define these constants myself, traditionally in uppercase:<\/p>\n<p><code>#define TRUE 1<br \/>\n#define FLASE 0<\/code><\/p>\n<p>I still default to this definition in my code. But occasionally I use these definitions, which was taught to me by a C guru back in the 1980s:<\/p>\n<p><code>#define FALSE 0<br \/>\n#define TRUE !FALSE<\/code><\/p>\n<p>I&#8217;m rather fond of this method.<\/p>\n<p>All this stuff goes away once your compiler adopts the C23 standard. Until then, these are your options should you elect to include the <code>stdbool.h<\/code> header file. Then you can freely play with Boolean values, which I am eager to show you in next week&#8217;s Lesson.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>George Boole would be proud. <a href=\"https:\/\/c-for-dummies.com\/blog\/?p=7739\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2],"tags":[],"class_list":["post-7739","post","type-post","status-publish","format-standard","hentry","category-main"],"_links":{"self":[{"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/7739","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=7739"}],"version-history":[{"count":2,"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/7739\/revisions"}],"predecessor-version":[{"id":7750,"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/7739\/revisions\/7750"}],"wp:attachment":[{"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=7739"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=7739"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=7739"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}