I saw a post on SO about using boolean types in C. One of the answers listed four ways to implement boolean types, the second and third way being:
typedef enum { false, true } bool;
and
typedef int bool;
enum { false, true };
The first one confused me at first because I had never seen an enum
being used as a type. Since enum
defines integer constants, I thought it was the same thing as the second one but slightly more confusing.
So, how does using enum
as a type work? Is there a difference between using enum
as a type and using an integer type, defining the enum
elsewhere? Most importantly, why would someone use enum
as a type?