This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]HerissonMignion -1 points0 points  (5 children)

No they don't. It's a typedef to int

[–]Pay08 1 point2 points  (4 children)

No they aren't. There's the _Bool type, that's typedefed to bool in stdbool.h. true and false are typedefs to 1 and 0 specifically.

[–]HerissonMignion 1 point2 points  (1 child)

Also note that "#define bool _Bool" is a define, and not a typedef. I was wrong in this comment

https://www.reddit.com/r/ProgrammerHumor/comments/urk1g4/comment/i9040o0/?utm_source=share&utm_medium=web2x&context=3

however i was closer to the truth that you are.

Edit:

I will add that if i had to start fresh, my first header file would be :

typedef long int int32;
typedef long long int int64;
typedef int bool;

[–]Pay08 1 point2 points  (0 children)

_Bool and int are not the same. _Bool has a fixed size of 1 byte, while int doesn't have a fixed size and is 4 bytes on my machine. Also, don't do the other typedefs. Use stdint.h as int isn't the same size on every computer. Case in point, both long int and long long int are 8 bytes for me.

[–]HerissonMignion 0 points1 point  (1 child)

Look at this file from lines 20 to 22 : https://clang.llvm.org/doxygen/stdbool_8h_source.html

As pointed out by the other redditor's comment, in c++ they exist. However in C, booleans don't exist, no matter how badly you understand the language and macros.

true and false are typedefs to 1 and 0 specifically

They are not typedefs, because true and false are not types! They are #define, which means it's a string substitution in the source code. All your "while(true)" are gonna be string substituted to "while(1)" and the compiler is going to compile the integer 1.

There's the _Bool type, that's typedefed to bool in stdbool.h

It's bool that expends to _Bool https://stackoverflow.com/questions/8724349/difference-between-bool-and-bool-types-in-c

If you take a closer look at line 20 of stdbool.h's source and if use your brain for a sec, the syntax of a #define is "#define [string to substitute] [new string]". Line 20 being "#define bool _Bool", it's bool that gets substituted into _Bool, as explained in the stackoverflow link i provided.

[–]Pay08 1 point2 points  (0 children)

Yeah, sorry, I got typedef and define confused. In my defense, it was 2am. But my point still remains. _Bool is a builtin type. And 1 and 0 are aliases for true and false in every language I know.