哪些平台比8位字符以外的东西? [英] What platforms have something other than 8-bit char?

查看:63
本文介绍了哪些平台比8位字符以外的东西?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

然后每一个现在,有人在SO指出,<一个href=\"http://stackoverflow.com/questions/437470/type-to-use-to-re$p$psent-a-byte-in-ansi-c89-90-c/437640#437640\"><$c$c>char (又名字节)未必是8位的。

Every now and then, someone on SO points out that char (aka 'byte') isn't necessarily 8 bits.

看来,8位字符几乎是普遍的。我本来以为,对于主流平台,就必须有一个8位字符,以确保其在市场上的生存能力。

It seems that 8-bit char is almost universal. I would have thought that for mainstream platforms, it is necessary to have an 8-bit char to ensure its viability in the marketplace.

无论是现在还是过去,平台使用什么字符不是8位,他们为什么会从正常的8位有什么不同?

Both now and historically, what platforms use a char that is not 8 bits, and why would they differ from the "normal" 8 bits?

在写code和思考跨平台支持(例如用于一般用途的库),什么样的代价是值得给予非8位字符<平台/ code>?

When writing code, and thinking about cross-platform support (e.g. for general-use libraries), what sort of consideration is it worth giving to platforms with non-8-bit char?

在过去,我已经遇到了一些ADI公司的DSP为其字符为16位。 DSP是一个有点小众的架构,我想的。 (话又说回来,当时手工codeD汇编轻松击败可用的C编译器可以做什么,所以我并没有真正得到与该平台基于C太多经验。)

In the past I've come across some Analog Devices DSPs for which char is 16 bits. DSPs are a bit of a niche architecture I suppose. (Then again, at the time hand-coded assembler easily beat what the available C compilers could do, so I didn't really get much experience with C on that platform.)

推荐答案

字符还对德州仪器的C54x的DSP,它打开了,例如在OMAP2 16位。还有其他的DSP在那里与16位和32位字符。我想,我甚至听到了24位DSP,但我不记得是什么,所以也许我想象的。

char is also 16 bit on the Texas Instruments C54x DSPs, which turned up for example in OMAP2. There are other DSPs out there with 16 and 32 bit char. I think I even heard about a 24-bit DSP, but I can't remember what, so maybe I imagined it.

另一个考虑是,POSIX任务 CHAR_BIT == 8 。所以,如果你正在使用POSIX你可以假定它。如果有人以后需要端口code到近执行POSIX,那恰好就可以使用这个功能,但是不同的尺寸字符,那是他们的运气不好。

Another consideration is that POSIX mandates CHAR_BIT == 8. So if you're using POSIX you can assume it. If someone later needs to port your code to a near-implementation of POSIX, that just so happens to have the functions you use but a different size char, that's their bad luck.

在一般情况下,虽然,我认为这是几乎总是更容易解决问题,而不是去想它。只需键入 CHAR_BIT 。如果你想要一个确切的8位类型,使用中int8_t 。您code会大肆编译失败的实现,这些都是不提供的,而是默默地用大小,你没想到的。最起码,如果我打,我​​有一个很好的理由去假设它的情况下,那么我会断言它。

In general, though, I think it's almost always easier to work around the issue than to think about it. Just type CHAR_BIT. If you want an exact 8 bit type, use int8_t. Your code will noisily fail to compile on implementations which don't provide one, instead of silently using a size you didn't expect. At the very least, if I hit a case where I had a good reason to assume it, then I'd assert it.

这篇关于哪些平台比8位字符以外的东西?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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