字符串常量的二进制存储

编程入门 行业动态 更新时间:2024-10-24 08:22:36
本文介绍了字符串常量的二进制存储的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

假设我按如下方式定义了一个char *变量: char * s ="?" ;; 实际得到什么放进二进制文件?据推测,它存储在 源文件的编码中。我对吗?或者它是编译器/平台 依赖? C规范建议字符串常量映射到 实现定义对执行角色成员的态度 设定。这是否意味着某些编译器在运行时在源代码集和执行字符集之间执行iconv-esque转换 ?如果是这样,那么 这意味着strlen的结果可能因执行而有所不同 字符集? 在此先感谢。

解决方案

Ross说:

假设我定义了一个char *变量如下: char * s ="?" ;; 我不知道你在那里写了什么,但是在我的显示器上我可以看到一点 白色方块。 (只是一个快速提示:指向字符串时使用const char * literals。) 实际上放入二进制文件的内容是什么? 这取决于。该值甚至可能不会进入二进制,取决于是否使用s 。但通常字符的编码点会出现在某个地方的二进制文件中。 据推测,它存储在源文件的编码中。我对吗?或者是编译器/平台依赖吗?

非常多。 < snip> - Richard Heathfield Usenet是一个奇怪的地方 - dmr 29/7/1999 www.cpax.uk 电子邮件:rjh在上面的域名(但显然放弃了www)

Richard Heathfield写道: 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 www.cpax.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?

更多推荐

字符串常量的二进制存储

本文发布于:2023-11-30 11:37:01,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1649828.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:常量   字符串

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!