簡體   English   中英

uint64_t 數組和 uint8_t 數組之間的 cpp 標准樣式轉換

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

我正在尋找一種 cpp“std-style”方式來訪問與 uint64_t 數組和 uint8_t 數組相同的靜態數組,以下是我如何在 C 中看到它解決的示例,無需位操作:

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

// array.u8[13];

或者,

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

實際上只有一種方法可以轉換為指向許多char類型之一的指針。 如果你想混合一些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