知识卡片
字节与C字符串字面量
b"A" 表示单字节的数组引用,b'A' 表示数值为 65 的 u8。字节字面量可直接使用 ASCII,也可加 \xHH 指定任意字节,整体不受合法 UTF-8 的约束。与 C 接口交换零结尾字符串时,可用 c"main" 得到 &CStr,底层含末尾的额外零字节。
关联阅读:[[文本类型匹配外部边界]]。
这张卡片看不懂?
这张卡片已通过人工审查,不再接受失败反馈。
已有反馈 · 0 条
还没有人提交反馈。
在整书笔记中的位置
原书出处 · 1 处
- Fundamental Types 外部接口决定文本的表示 · 查看原书依据
C string. It is like the regular string "main" except it is null-terminated; that is, it’s stored with an extra 0 byte to indicate the
参考来源
- 位置:《Programming Rust Fast, Safe Systems Development, 3rd ed. (First Early Release)》第02章《Fundamental Types》|外部接口决定文本的表示,来源项目 `book-source`,`extracted/Programming Rust Fast, Safe Systems Development, 3rd ed. (First Early Release)/_epub-src/OEBPS/ch02.xhtml#other-string-like-types`
- 结论依据:原文以 ELF 文件标识和 C 接口字符串为例,对照 b 前缀与 c 前缀形成的不同类型,随后解释 b 字节字面量的取值。
- 原始内容:C string. It is like the regular string "main" except it is null-terminated; that is, it’s stored with an extra 0 byte to indicate the