Is char signed or unsigned by default?

前端 未结 7 809
佛祖请我去吃肉
佛祖请我去吃肉 2020-11-21 06:49

In the book \"Complete Reference of C\" it is mentioned that char is by default unsigned.

But I am trying to verify this with GCC as well as Visual Stud

7条回答
  •  难免孤独
    2020-11-21 07:19

    Now, we known the standard leaves that up to the implementation.

    But how to check a type is signed or unsigned, such as char?

    I wrote a macro to do this:

    #define IS_UNSIGNED(t) ((t)~1 > 0)

    and test it with gcc, clang, and cl. But I do not sure it's always safe for other cases.

提交回复
热议问题