CHAR_BIT = 32的实现 [英] Implementations with CHAR_BIT=32

查看:83
本文介绍了CHAR_BIT = 32的实现的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

标准允许实现CHAR_BIT = 32和sizeof

char = sizeof short = sizeof int = sizeof long = 1,对吧?


出于好奇,有没有人知道实际的实施有这个?b / b $

$

解决方案

Skarmander< in ***** @ dontmailme.com>写道:

该标准允许实现CHAR_BIT = 32和sizeof
char = sizeof short = sizeof int = sizeof long = 1,对吧?


是的。很多其他编写良好的代码会在这样的(托管)实现上发生故障,因为EOF现在处于签名字符的范围内。

。另一个问题是,可能无法声明一组

UCHAR_MAX元素; UCHAR_MAX + 1

元素是违反约束的。我相信其他常见的b $ b b实践也会失败。

出于好奇,有没有人知道有这个实际的实现?




我听说有些DSP使用这个型号,但没有托管

实现。

-

" ...几乎让你想知道为什么海森堡在不确定性原则中不包括postinc / dec运算符

。这当然使上述内容相当于

Schrodinger的指针......"

--Anthony McDonald


Ben Pfaff写道:

Skarmander< in ***** @ dontmailme.com>写道:

该标准允许实现CHAR_BIT = 32和sizeof
char = sizeof short = sizeof int = sizeof long = 1,对吧?



是的。很多其他编写良好的代码会在这样的(托管)实现上出现故障,因为EOF现在处于签名字符的范围内。另一个问题是声明一个UCHAR_MAX元素数组可能是不可能的; UCHAR_MAX + 1
元素是违反约束的。我确信其他常见的
做法也会失败。



< snip>

我想象一下UCHAR_MAX元素的数组通常是在假设char不显着大于b $ b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b />
失败),并且字符集是小的。对于某些合理的值,小的
,其中不包括32位。 (这可能仍然会保持
持有)。


这个或应用程序真的需要8位字节,但是使用

UCHAR_MAX,因为它看起来更整洁(可以认为是一个错误,而不仅仅是一个假设)。


我不太明白EOF问题但是。这可能只是我缺乏想象力,但是你能给出一个失败的代码片段吗?


S.


Skarmander< in ***** @ dontmailme.com>写道:

但我并没有完全看到EOF问题。这可能只是我缺乏想象力,但是你能给出一个失败的代码片段吗?




像这样的东西经常被用来检测结束-of-file或错误:

if(getc(file)== EOF){

/ * ...处理错误或文件结束... * /

}

如果" int"和char具有相同的范围,然后返回值

EOF并不一定意味着错误或文件结尾是

遇到。

-

为了充分利用这本书,我强烈建议你阅读它。

- 理查德希思菲尔德


The standard allows an implementation where CHAR_BIT = 32 and sizeof
char = sizeof short = sizeof int = sizeof long = 1, right?

Just out of curiosity, does anyone know actual implementations that have
this?

S.

解决方案

Skarmander <in*****@dontmailme.com> writes:

The standard allows an implementation where CHAR_BIT = 32 and sizeof
char = sizeof short = sizeof int = sizeof long = 1, right?
Yes. A lot of otherwise well-written code would malfunction on
such a (hosted) implementation, because EOF is now in the range
of a signed char. Another problem is that declaring an array of
UCHAR_MAX elements is probably not possible; UCHAR_MAX + 1
elements is a constraint violation. I''m sure that other common
practices would fail as well.
Just out of curiosity, does anyone know actual implementations that have
this?



I have heard that some DSPs use this model, but not hosted
implementations.
--
"...Almost makes you wonder why Heisenberg didn''t include postinc/dec operators
in the uncertainty principle. Which of course makes the above equivalent to
Schrodinger''s pointer..."
--Anthony McDonald


Ben Pfaff wrote:

Skarmander <in*****@dontmailme.com> writes:

The standard allows an implementation where CHAR_BIT = 32 and sizeof
char = sizeof short = sizeof int = sizeof long = 1, right?


Yes. A lot of otherwise well-written code would malfunction on
such a (hosted) implementation, because EOF is now in the range
of a signed char. Another problem is that declaring an array of
UCHAR_MAX elements is probably not possible; UCHAR_MAX + 1
elements is a constraint violation. I''m sure that other common
practices would fail as well.


<snip>
I''d imagine that declaring an array of UCHAR_MAX elements is most
commonly done under the assumption that `char'' is not significantly
larger than necessary to hold the characters in the character set (which
fails), and that the character set is "small" for some reasonable value
of "small", which does not include "32 bits" (this will probably still
hold).

Either that or the application really wants 8-bit bytes, but is using
UCHAR_MAX because it looks neater (which could be considered a bug, not
just an assumption).

I don''t quite see the EOF problem, though. It''s probably just my lack of
imagination, but could you give a code snippet that fails?

S.


Skarmander <in*****@dontmailme.com> writes:

I don''t quite see the EOF problem, though. It''s probably just my lack of
imagination, but could you give a code snippet that fails?



Something like this is often used to detect end-of-file or error:
if (getc(file) == EOF) {
/* ...handle error or end of file... */
}
If "int" and "char" have the same range, then a return value of
EOF doesn''t necessarily mean that an error or end-of-file was
encountered.
--
"To get the best out of this book, I strongly recommend that you read it."
--Richard Heathfield


这篇关于CHAR_BIT = 32的实现的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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