在 C++ 程序中,我有一个 char* 指向包含 BUFFER_SIZE 个字符的数组的开头(每个字符的大小为一个字节)。 我现在想在 NS3 模拟中使用该代码,其中数据包将 uint8_t const* 作为输入,指向缓冲区。
我应该怎么做才能创建指向第一个提到的缓冲区的“uint8_t const*”?
最佳答案
您必须使用 reinterpret_cast
:
int main () {
char buffer[10];
reinterpret_cast<unsigned char const *>(buffer);
}
或使用 C 风格的转换:
int main () {
char buffer[10];
(unsigned char const *)buffer;
}
关于c++ - 如何让 uint8_t const* 指向与 char* 相同的地址?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10095499/