简体   繁体   English

uint64_t 数组和 uint8_t 数组之间的 cpp 标准样式转换

[英]cpp std-style conversion between uint64_t array and uint8_t array

I'm looking for a cpp "std-style" way to access an the same static array as uint64_t array and uint8_t array, here are examples how I saw it solved in C, without bit operations:我正在寻找一种 cpp“std-style”方式来访问与 uint64_t 数组和 uint8_t 数组相同的静态数组,以下是我如何在 C 中看到它解决的示例,无需位操作:

union {
    uint64_t u64[16];
    uint8_t u8[128];
} array;

// array.u8[13];

or,或者,

uint64_t u64_array[16];
uint8_t* u8_array = u64_array;
// u8_array[13];

There really only is the way of casting to a pointer to one of the many char types.实际上只有一种方法可以转换为指向许多char类型之一的指针。 If you want to mix in some std ishness how about this:如果你想混合一些std的东西怎么办:

uint64_t u64_array[16];
auto raw = std::span{(uint8_t*)u64_array, 128};

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

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