字符串常量的二进制存储 [英] Binary storage of string constants

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

问题描述

假设我按如下方式定义了一个char *变量:


char * s ="?" ;;


实际得到什么放进二进制文件?据推测,它存储在

源文件的编码中。我对吗?或者它是编译器/平台

依赖?


C规范建议字符串常量映射到

实现定义对执行角色成员的态度

设定。这是否意味着某些编译器在运行时在源代码集和执行字符集之间执行iconv-esque转换

?如果是这样,那么

这意味着strlen的结果可能因执行而有所不同

字符集?


在此先感谢。

解决方案

Ross说:

假设我定义了一个char *变量如下:

char * s ="?" ;;


我不知道你在那里写了什么,但是在我的显示器上我可以看到一点

白色方块。 (只是一个快速提示:指向字符串时使用const char *

literals。)

实际上放入二进制文件的内容是什么?


这取决于。该值甚至可能不会进入二进制,取决于是否使用s
。但通常字符的编码点会出现在某个地方的二进制文件中。

据推测,它存储在源文件的编码中。我对吗?或者是编译器/平台依赖吗?




非常多。


< snip>


-

Richard Heathfield

Usenet是一个奇怪的地方 - dmr 29/7/1999
http://www.cpax.org.uk

电子邮件:rjh在上面的域名(但显然放弃了www)


Richard Heathfield写道:
< blockquote class =post_quotes> Ross说:

假设我按如下方式定义一个char *变量:

char * s =" ??" ;



我不知道你在那里写了什么,但在我的显示器上我可以看到一个小白色方块。




在这个新闻阅读器(knode)中看起来像欧元。当我尝试将它变成一个命令窗口(konsole)时,它似乎变成了一个零宽度的b $ b字符 - 而且退格在命令提示符中擦掉了一个空格!


-

Chris飞向左翼的飞机的漂亮图标 Dollin

摇滚不是事实。岩石是一块石头。


是的,它应该是一个欧元符号。


任何想法那么在运行时会发生什么?是否有可能将字符串

转换为执行chacacter集,或者它是否只是保留

''在源字符集中是''这同样适用于角色

常数吗?


Suppose I define a char* variable as follows:

char *s = "?";

What actually gets put into the binary? Presumably, it gets stored in
the encoding of the source file. Am I right? Or is it compiler/platform
dependent?

The C spec suggests that string constants get mapped in an
implementation-defined manner to members of the execution character
set. Does this mean that some compilers perform iconv-esque conversion
between the source and execution character sets at runtime? If so, does
this mean the result of strlen(s) may vary depending on the execution
character set?

Thanks in advance.

解决方案

Ross said:

Suppose I define a char* variable as follows:

char *s = "?";
I don''t know what you wrote there, but on my display I can see a little
white square. (Just a quick tip: use const char * when pointing at string
literals.)
What actually gets put into the binary?
It depends. The value might not even make it into the binary, depending on
whether s gets used. But typically the coding point of the character will
appear in the binary somewhere.
Presumably, it gets stored in
the encoding of the source file. Am I right? Or is it compiler/platform
dependent?



Very much so.

<snip>

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at above domain (but drop the www, obviously)


Richard Heathfield wrote:

Ross said:

Suppose I define a char* variable as follows:

char *s = "??";



I don''t know what you wrote there, but on my display I can see a little
white square.



Looks like a Euro here in this newsreader (knode). And when I tried pasting
it into a command window (konsole), it seemed to become a zero-width
character - and backspacing rubbed out a space in the command prompt!

--
Chris "nice icon for a planeship flying left" Dollin
A rock is not a fact. A rock is a rock.


Yeah, it was supposed to be a Euro symbol.

Any idea what happens at runtime, then? Is it possible that the string
gets converted into the execution chacacter set, or will it just remain
''as is'' in the source character set? Does the same apply to character
constants?


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

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