How to fix C error 'unknown type name bool'
Problem:
You have C code like
bool mybool;
but when you try to compile it you see an error message like
main.c: In function ‘main’:
main.c:3:5: error: unknown type name ‘bool’; did you mean ‘_Bool’?
bool mybool;
^~~~
_Bool
Solution
Add
#include <stdbool.h>
at the top of the source file where the error occured.
The reason for this error is that bool
is not a standard type in C (like int
or char
) but only in stdbool.h
.