Questions tagged [stdbool]
15 questions
14
votes
3 answers
Why use instead of _Bool?
Any time I had the need of a Boolean type I was told to either create one, or better yet, use stdbool.h.
Since stdbool.h uses typedef bool _Bool, is there a reason to use the header instead just using type _Bool? Is it just for the additional macros…

CIsForCookies
- 12,097
- 11
- 59
- 124
4
votes
2 answers
Is (bool) cast reliably 0 or 1?
From some reading on Stack Overflow, I gather that bool, as defined in stdbool.h, is a macro that expands to the built-in type _Bool, and that true is defined as 1 and false is defined as 0.
Is casting to bool guaranteed to return a value of 0 or 1?…

StoneThrow
- 5,314
- 4
- 44
- 86
3
votes
2 answers
Why is stdbool.h deprecated?
The C standard now says:
The ability to undefine and redefine the macros bool, true, and false is an obsolescent feature and may be removed in a future version.
That is, stdbool.h is deprecated. But no rationale is given and I couldn't find one. …

Lærne
- 3,010
- 1
- 22
- 33
3
votes
4 answers
Writing a function in C that returns a boolean
As C does not have boolean types, how can I write a function like this in C:
bool checkNumber()
{
return false;
}

olidev
- 20,058
- 51
- 133
- 197
2
votes
1 answer
Is failure to implicitly convert a pointer to _Bool a compiler deficiency?
Answers to this question state that scalars can be converted to _Bool and that the resulting integer value of the _Bool will be 0 or 1.
The accepted answer to this question points out that pointers are scalars.
Is a failure to implicitly convert a…

StoneThrow
- 5,314
- 4
- 44
- 86
2
votes
0 answers
visual studio 2012 compiler does not recognize stdbool.h
I'm writing a header file for binary search tree, however when i compiled visual studio 2012 compiler does not recognized stdbool.h header.I got this error:
error C1083: Cannot open include file: 'stdbool.h': No such file or directory
why am i…

bluebk
- 169
- 1
- 6
- 21
1
vote
0 answers
Scan boolean value using library
is it possible to get a scanf of a value generated with the standard library ''?
For example if you wanted to scan the value of 'bool check;' where check is the name how can I do this without assigning it to another element?
Here is a…

Leonardo
- 123
- 2
- 13
1
vote
1 answer
Why is C99's bool a macro rather than a typedef?
Why does the boolean type support introduced in C99 use the preprocessor rather than the language's own facilities? Specifically, why do we have:
#define bool _Bool
#define true 1
#define false 0
in rather than:
typedef _Bool…

einpoklum
- 118,144
- 57
- 340
- 684
1
vote
1 answer
MISRA C 2004 and c99
Rule 1.1 of the MISRA C 2004 specifies that the spec covers c90 and not c99.
I would like to use the stdint and stdbool libraries instead of coding my own. Has anyone made this exception in their MISRA implementation?

JeffV
- 52,985
- 32
- 103
- 124
0
votes
2 answers
Why is scanf working abnormally for bool input in C?
I am trying to get input for 3 bool variables and 1 int variable. Even though I give input correctly, it is not behaving right.
I am using %d as format specifier for bool in stdbool.h as suggested by @taufique in Format specifier in scanf for bool…

Alagusankar
- 111
- 1
- 8
0
votes
4 answers
Boolean in C Programming
So , unfortunately I encountered another problem with a program I'm trying to create. First of all I'm totally new to C Programming and I'm trying to create a Word Search .
I have this piece of code which is in C++ and I'm trying to turn it into C…

Takari
- 29
- 2
- 3
- 8
0
votes
1 answer
What's the purpose of _Bool in C99?
As for stdbool.h, I can see some people wanting to have constants for true and false and a type named bool if only for clarity (though I'm not really one of them, personally).
However, what's the purpose of the actual _Bool type? Why not just define…

Dolda2000
- 25,216
- 4
- 51
- 92
0
votes
2 answers
Building msgpack-python on Solaris 10 - Use of is valid only in a c99 compilation environment
I'm trying to build the python module msgpack-python on Solaris with the Sun compiler and am getting this error during the python ./setup.py build:
/opt/SUNWspro/bin/cc -DNDEBUG -O -xO3 -m32 -xarch=sparc -I/opt/csw/include -xcode=pic32…

user1522264
- 123
- 1
- 1
- 5
-1
votes
1 answer
Why do I get an error when I use %d in scanf when I use stdbool.h?
There are times when I use stdbool.h while practicing coding. At this time, if the format modifier of scanf is given as %d, the following error message occurs.
c:\project\hello\hello\hello.c(11): warning C4477: 'scanf' : format string '%d' requires…

HJS
- 3
- 1
-3
votes
2 answers
What does do?
What does the do when using it in a C code?
I searched for it on the Wikipedia and didn't get answers in my language, i would love that someone will explain to me what it means.

Mr. Robot
- 13
- 3