加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

c – sizeof(int)> = 2和sizeof(long)> = 4:对于任何实现

发布时间:2020-12-16 10:11:41 所属栏目:百科 来源:网络整理
导读:B.Stroustrup在他的新书(TCPL第4版)第6.2.8节中说明如下: Some of the aspects of C++’s fundamental types,such as the size of an int,are implementation defined (§6.1). 稍后,在第150页中,我们有以下示例: int_least16_t y; // at least 2 bytes (j
B.Stroustrup在他的新书(TCPL第4版)第6.2.8节中说明如下:

Some of the aspects of C++’s fundamental types,such as the size of an
int,are implementation defined (§6.1).

稍后,在第150页中,我们有以下示例:

int_least16_t y; // at least 2 bytes (just like int)
int_least32_t yy // at least 4 bytes (just like long)

我对这两个注释的解释是int(或long)的大小是实现定义的,但它们的最小大小总是分别等于2和4个字节.也就是说,对于任何实现,sizeof(int)> = 2并且sizeof(long)> = 4.

首先,这是正确的吗?如果是这样,标准中的内容在哪里?

解决方法

不,并非总是如此. char可能是64位类型,其中casesizeof(int)和sizeof(long)都可以是1.

但是,你保证的是sizeof(int)* CHAR_BIT> = 16和sizeof(long)* CHAR_BIT> = 32,因为int和long分别需要至少16位和32位.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读