gpt4 book ai didi

c - 在不强制转换的情况下对 unsigned char * 使用字符串方法

转载 作者:太空宇宙 更新时间:2023-11-04 04:44:00 24 4
gpt4 key购买 nike

我注意到我使用了几种字符串方法,例如

strcpy(userAmount, pch);

unsigned char* 缓冲区上,没有 转换。例如,这些变量的定义如下

   u8 * pch = NULL;
u8 userAmount[255] = {0};

到目前为止它运行良好。

这是预期的行为吗?我要继续这样使用吗?

到目前为止,缓冲区存储的 ASCII 文本,将来可能会保存 UTF8 - 在这种情况下情况会有所不同(例如,在转换、缓冲区类型方面)吗?

最佳答案

当标准类型 (char) 可以时,为什么要使用一些非标准类型 (u8?)?

不过,你的方法应该没问题。

来自 C11 标准(斜体 由我):

7.24.1 String function conventions

The header string.h declares one type and several functions, and defines one macro useful for manipulating arrays of character type and other objects treated as arrays of character type.

[...]

For all functions in this subclause, each character shall be interpreted as if it had the type unsigned char (and therefore every possible object representation is valid and has a different value).

关于c - 在不强制转换的情况下对 unsigned char * 使用字符串方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23011138/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com