加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

c – 将char数组转换为unsigned char *

发布时间:2020-12-16 03:35:23 所属栏目:百科 来源:网络整理
导读:有没有办法将char []转换为unsigned char *? char buf[50] = "this is a test"; unsigned char* conbuf = // what should I add here 解决方法 虽然它在技术上可能不是100%合法,但这将起作用reinterpret_cast unsigned char *(buf). 这不是100%技术合法的
有没有办法将char []转换为unsigned char *?
char buf[50] = "this is a test"; 
unsigned char* conbuf = // what should I add here

解决方法

虽然它在技术上可能不是100%合法,但这将起作用reinterpret_cast< unsigned char *>(buf).

这不是100%技术合法的原因是由于5.2.10 expr.reinterpret.cast bullet 7.

A pointer to an object can be explicitly converted to a pointer to an object of a different type. original type yields the original pointer value,the result of such a pointer conversion is unspecified.

我认为* reinterpret_cast< unsigned char *>(buf)=’a’未指定,但* reinterpret_cast< char *>(reinterpret_cast< unsigned char *>(buf))=’a’是正常的.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读