8
What is the most appropriate way to simulate the type bool
in C? My teacher did it in a very simple way.
#define bool int
But I also found an excellent answer here (follows a copy of the code).
// Criando a enumeração:
enum boolean {
true = 1, false = 0
};
// Permitindo a sua declaração como um tipo qualquer:
typedef enum boolean bool;
// Agora podemos escrever e compilar os códigos como:
int main () {
bool b = true;
if (b) {
b = false;
}
return 0;
}
What are the pros and cons of both types of statement and where they can cause me headache in the future if I implement them in a library?