c ++整数数据类型 [英] c++ integer data types

查看:84
本文介绍了c ++整数数据类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写了一个简短的页面作为c ++整数数据类型的快速参考。

欢迎任何反馈: http://www.somacon.com/blog/page11.php

解决方案

< blockquote> Shailesh Humbad写道:


我写了一个简短的页面作为c ++整数数据类型的快速参考。任何
欢迎回复: http://www.somacon.com/ blog / page11.php




" char的大小保证至少为8位。实际的

大小是一个未指定的,系统相关的单位,可以代表

实现的字符集。

错误! char的大小是*总是* 1个字节,并不总是8位。

这是1个字节并不总是8位(但大多数时候都是)。


我们使用char,signed char和unsigned char,不仅要处理

字符,还要处理字节。

例如任何对象C ++可以安全地被视为(和读取)作为无符号字符的序列



任何POD对象也可以作为一系列普通字符读取。你可以将
复制到相同大小的unsigned char / plain char数组并创建第一个对象的
a(浅)副本。

------------------------------------------------ -------------------------

引入了一种新类型,很长一段时间,保证是在

至少64位。请参阅limits.h以获取系统上的范围。


错误,long long不是C ++ 98的一部分,也省略了< limits>。所以

上面这样会更好:

"在< limits>中使用numeric_limits (或C子集< climits>常数)到

获取系统中所有内置类型的范围。


-

Ioannis Vranos

http://www23.brinkster .com / noicys


* Ioannis Vranos:

Shailesh Humbad写道:


我写了一个简短的页面作为c ++整数数据类型的快速参考。任何
欢迎回复: http://www.somacon.com/ blog / page11.php



" char的大小保证至少为8位。实际的
大小是一个未指定的,依赖于系统的单元,可以代表
实现的字符集。

错了! char的大小是*总是* 1个字节,并不总是8位。
这是1个字节并不总是8位(但大多数情况下)。




我在引用的段落中没有看到任何错误信息。它没有提到

字节,并且由于C ++采用了来自C的CHAR_MIN和CHAR_MAX(疯狂的

handwaiving以分散学者的注意力)继承了C'对>的保证。 = 8位。


-

答:因为它弄乱了人们通常阅读文本的顺序。

Q :为什么这么糟糕?

A:热门帖子。

问:usenet和电子邮件中最烦人的是什么?


Alf P. Steinbach写道:

我在引用的段落中没有看到_wrong_;它没有提到
字节,并且由于C ++采用了来自C的CHAR_MIN和CHAR_MAX(疯狂的,用来分散学者的注意力)继承了C'对> = 8位的保证。



是的。也许他应该取代尺寸这个词。用宽度一词或者

" bit-size"。


-

Ioannis Vranos

http://www23.brinkster.com/noicys


I wrote a short page as a quick reference to c++ integer data types.
Any feedback welcome: http://www.somacon.com/blog/page11.php

解决方案

Shailesh Humbad wrote:


I wrote a short page as a quick reference to c++ integer data types. Any
feedback welcome: http://www.somacon.com/blog/page11.php



"The size of a char is guaranteed to be at least eight bits. The actual
size is an unspecified, system-dependent unit that can represent the
implementation''s character set."
Wrong! The size of char is *always* 1 byte, which is not always 8 bits.
That is 1 byte is not always of 8 bits (but most times it is).

We use char, signed char and unsigned char, not only to deal with
characters, but also to deal with bytes.
For example any object of C++ can be considered (and read) as a sequence
of unsigned chars safely.
Any POD object can be read as a sequence of plain chars too. And you can
copy it to an unsigned char/plain char array of the same size and create
a (shallow) copy of the first object.
-------------------------------------------------------------------------
"A new type has been introduced, long long, that is guaranteed to be at
least 64 bits. See limits.h to get the ranges on your system."

Wrong, long long is not part of C++98 and also you omitted <limits>. So
the above would be better this way:
"Use numeric_limits in <limits> (or the C subset <climits> constants) to
get the ranges of all built in types in your system".

--
Ioannis Vranos

http://www23.brinkster.com/noicys


* Ioannis Vranos:

Shailesh Humbad wrote:


I wrote a short page as a quick reference to c++ integer data types. Any
feedback welcome: http://www.somacon.com/blog/page11.php



"The size of a char is guaranteed to be at least eight bits. The actual
size is an unspecified, system-dependent unit that can represent the
implementation''s character set."

Wrong! The size of char is *always* 1 byte, which is not always 8 bits.
That is 1 byte is not always of 8 bits (but most times it is).



I don''t see anything _wrong_ in the quoted passage; it doesn''t mention
bytes, and since C++ adopts CHAR_MIN and CHAR_MAX from C it (frantic
handwaiving to distract academics) inherits C''s guarantee of >= 8 bits.

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?


Alf P. Steinbach wrote:

I don''t see anything _wrong_ in the quoted passage; it doesn''t mention
bytes, and since C++ adopts CHAR_MIN and CHAR_MAX from C it (frantic
handwaiving to distract academics) inherits C''s guarantee of >= 8 bits.


Yes. Perhaps he should replace the word "size" with the word "width" or
"bit-size".

--
Ioannis Vranos

http://www23.brinkster.com/noicys


这篇关于c ++整数数据类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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