Louis I. answered 05/05/19
Computer Science Instructor/Tutor: Real World and Academia Experienced
Nope, C doesn't, but C++ does.
In practice, any simple C program can be compiled using the C++ compiler ... but for complex applications, you might have far too many little issues to fix, since ANCI C compilers are more "forgiving" that most C++ compilers.
A much more suitable approach would be to define a bi-value enum called bool using typedef - see below:
typedef enum { false, true } bool;
This effectively provides a Developer Defined Type called "bool" that can be used exactly as we use bool in C++ ....
// g++ will compile this without error, but gcc will not.
#include
int main() {
bool flag = true;
if( flag ) puts("ok");
return 0;
}
// both g++ and gcc will compile this.
#include <stdio.h>
typedef enum { false, true } bool;
int main() {
bool flag = false;
if( flag ) puts("ok");
return 0;
}