繁体   English   中英

嵌入式系统中的c char字符串和stdint.h uint8_t兼容性

[英]c char string and stdint.h uint8_t compatability in embedded system

我需要在C ++中将const char []转换为uint8_t。 最好的方法是什么

一种)

const uint8_t* a = (const uint8_t*)"string";  // I hate this cast, but it works

b)

const uint8_t* a = reinterpret_cast<const uint8_t*>("string");  // is this OK, is it safe?

为什么这不起作用?

const uint8_t* a = static_cast<const uint8_t*>("string");  // will not compile

第二种解决方案是“最正确”的方法。 reinterpret_cast将完全由编译器处理,并仅指向具有不同类型的结果位。 第一个解决方案是旧式的,通常不应在现代C ++中使用。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM