gpt4 book ai didi

c++ - 将带有 int 的 unsigned char 数组转换为 unsigned char

转载 作者:太空宇宙 更新时间:2023-11-04 16:23:59 25 4
gpt4 key购买 nike

有人可以帮我解决以下错误吗?在我尝试通过 buf 之前,我应该转换 len 吗?

int len=2;
unsigned char tmp[len + 1];
unsigned char * buf = &tmp;

错误是:

error: cannot convert 'unsigned char (*)[(((unsigned int)((int)len)) + 1)]' to 'unsigned char*' in assignment

最佳答案

如果你只是想要一个指向数组的指针,使用

unsigned char * buf = tmp;

顺便说一句,您声明 tmp 的方式使其成为 variable-length array (VLA)。从技术上讲,these are not allowed in C++ ,尽管许多编译器支持 VLA 作为扩展。

关于c++ - 将带有 int 的 unsigned char 数组转换为 unsigned char,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13859259/

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