为char签名或默认无符号? [英] Is char signed or unsigned by default?

查看:279
本文介绍了为char签名或默认无符号?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在这本书的C完整的参考中提到,char是在默认情况下未签名。

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

但我试图用GCC以及Visual Studio来验证这一点。它把它在默认情况下为签署。

But I am trying to verify this with GCC as well as Visual Studio. It is taking it as signed by default.

哪一个是正确的?

推荐答案

这本书是错误的。该标准并没有规定平原字符带符号。

The book is wrong. The standard does not specify if plain char is signed or unsigned.

事实上,该标准定义了三种不同的类型:字符符号字符 unsigned char型。如果您的#include< limits.h中> 再看看 CHAR_MIN ,你可以找出是否平原字符签署无符号(如 CHAR_MIN 小于0或等于0),但即使是这样,在三种类型是不同的的尽可能的标准而言。

In fact, the standard defines three distinct types: char, signed char, and unsigned char. If you #include <limits.h> and then look at CHAR_MIN, you can find out if plain char is signed or unsigned (if CHAR_MIN is less than 0 or equal to 0), but even then, the three types are distinct as far as the standard is concerned.

这篇关于为char签名或默认无符号?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆