多字符常量 [英] multi-character constant

查看:138
本文介绍了多字符常量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,


多字符常量的目的究竟是什么.. ???

Hi all,

what exactly is the purpose of multi-character constant..???

推荐答案

aa*****@gmail.com 写道:

大家好,


多字符常量的目的究竟是什么.. ???
Hi all,

what exactly is the purpose of multi-character constant..???



你的意思是UCN吗?


-

Tor< bw *** *@wvtqvm.vw | tr i-za-h a-z>

Do you mean UCN?

--
Tor <bw****@wvtqvm.vw | tr i-za-h a-z>


Tor Rustad写道:
Tor Rustad wrote:
aa ***** @ gmail.com 写道:

>大家好,

多字符常数究竟是什么目的.. ???
>Hi all,

what exactly is the purpose of multi-character constant..???



你的意思是UCN吗?


Do you mean UCN?



编号见6.4.4.4p10:的价值一个整数字符常量

包含多个字符(例如''ab''),或包含一个

字符或转义序列,不会映射到单个字符byte

执行字符,是实现定义的。


我不知道哪些实现支持

multi的有意义的定义-character常量,也不是他们使用它们的原因。我想,实现定义行为的可能形式之一可能是:/ b $ b $ i ='' ab'';





memcpy(& i," ab",sizeof i)具有完全相同的效果;


我不确定它会有多大用处。

No. See 6.4.4.4p10: "The value of an integer character constant
containing more than one character (e.g., ''ab''), or containing a
character or escape sequence that does not map to a single-byte
execution character, is implementation-defined."

I have no idea which implementations support meaningful definitions for
multi-character constants, nor what they use them for.I imagine that one
possible form of implementation defined behavior might be to have

int i = ''ab'';

have exactly the same effect as

memcpy(&i, "ab", sizeof i);

I''m not sure how useful that would be.


aa ***** @ gmail.com 写道:

到底是什么是多字符常量的目的.. ???
what exactly is the purpose of multi-character constant..???



这不是100%清楚你的意思;一个例子会有所帮助。


如果你的意思是''ab'',最好的答案就是如果你要b
问你,你不要不需要知道。所有标准都是(C99 6.4.4.4p10):


整数字符常量的值,包含超过

的一个字符(例如''' ab'')[...]是实现定义的。


实际上,''ab''的值可能是''a''* 256 + ''b''

或''b''* 256 +''a''。它会因编译器而异。


我见过它们实际使用的唯一地方是PalmOS软件,

其中,如果我回想一下,他们习惯于为应用程序提供独特的16位标签

。类似''XY'的'与'

应用程序的名称相关的东西比数字常量更容易记住。在那个

上下文中,实际值并不重要,只是每对
字符映射到一致且唯一的整数值。这取决于使用相同映射的每个编译器上的
,或者使用相同的编译器编译的所有应用程序都是



但是一个充分反常的编译器可以在法律上拥有所有这样的

常量具有值42.


避免这样的常量,除非你真的需要它们*和*你是准备

来处理他们本来就不便携的事实。


-

Keith Thompson(The_Other_Keith )< ks *** @ mib.org>

在圣地亚哥地区寻找软件开发工作。

我们必须做点什么。这是事情。因此,我们必须这样做。

- Antony Jay和Jonathan Lynn,是部长

It''s not 100% clear what you mean; an example would be helpful.

If you mean something like ''ab'', the best answer is that if you have to
ask, you don''t need to know. All the standard says is (C99 6.4.4.4p10):

The value of an integer character constant containing more than
one character (e.g., ''ab'') [...] is implementation-defined.

In practice, the value of ''ab'' is likely to be either ''a'' * 256 + ''b''
or ''b'' * 256 + ''a''. It will vary from one compiler to another.

The only place I''ve seen them actually used is in software for PalmOS,
where, if I recall correctly, they''re used to provide unique 16-bit tags
for applications. Something like ''XY'' that''s related to the name of the
application is easier to remember than a numeric constant. In that
context, the actual value doesn''t matter, just that each pair of
characters maps to a consistent and unique integer value. This depends
on every compiler using the same mapping, or on all applications being
compiled with the same compiler.

But a sufficiently perverse compiler could legally have all such
constants have the value 42.

Avoid such constants unless you really need them *and* you''re prepared
to deal with the fact that they''re inherently non-portable.

--
Keith Thompson (The_Other_Keith) <ks***@mib.org>
Looking for software development work in the San Diego area.
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"


这篇关于多字符常量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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