Is using char as a bool in C bad practice?

后端 未结 4 1111
逝去的感伤
逝去的感伤 2021-02-19 21:35

Is there any downside to using

typedef char bool;
enum boolean { false, true };

in C to provide a semantic boolean type?

4条回答
  •  被撕碎了的回忆
    2021-02-19 22:00

    In C99, you should be using stdbool.h, which defines bool, true, and false.

    Otherwise what you have is fine. Using just the enum may be a bit simpler, but if you really want to save space what you have works.

提交回复
热议问题