The title is self-explanatory: I want to serialize an arbitrary large amount of trivially copyable non array "stuff" into a buffer (for academic reaso ...
The title is self-explanatory: I want to serialize an arbitrary large amount of trivially copyable non array "stuff" into a buffer (for academic reaso ...
There is this nice feature in C++ where you can say the function has return type "auto" and compiler will figure it out. However, what if I return a p ...
Let's say I have this code: All I want is to interpret the bits from the bits variable as a float. I came to understand that this is called "type p ...
Just a heads up, I'm referencing from a working code, and I'm trying to implement the same method but with a CString. The below method that works, ca ...
I need to use a function func(uint8_t* buffer, uint size); supposing I can't change its parameters, I want to pass it a string. I have a vector<st ...
From what I understand, casting function pointers to different types is allowed by the C++ standard (as long as one never invokes them): int my_func( ...
Reading https://en.cppreference.com/w/cpp/language/reinterpret_cast I wonder what are use-cases of reinterpret_cast that are not UB and are used in pr ...
Plz check following c++ code: (nothing special, should be compliant to c++ 2nd edition from 1991) basic conditions class CNullable follows the well ...
I want dval to be of a certain value which when written in hexadecimal looks like this "0x543". Is there any danger doing this? Do you see a more ef ...
I am following a tutorial and I am using the following code to read a binary file into an array: My question is firstly why we could cast an array ...
For a long time I've used reinterpret_cast like this: static_assert(sizeof(int) == sizeof(float)); int a = 1; float b = *reinterpret_cast<float*&g ...
Example: Are std::function<void()> and std::function<std::monostate()> considered "similar" enough for reinterpret_cast to be safe? Ed ...
Disclaimer: I understand this is an unsafe operation and bad practice, I merely want to know if it's possible. Basically, I'm trying to convert an ob ...
How should one cast pointers to char*/const char*? Using reinterpret_cast? Or probably std::bit_cast? A simple example: This seems to works fine. ...
I am porting to C++11 a C code base that makes use of a number of custom intrusive data structures. In C, the usage patterns will typically look like ...
Why does the second example find 1100 instead of 0000 after storing the address in the int pointer and then reading the adjacent bits? Example 1: ...
I came across a code snippet where the bytes from a buffer were copied into a struct variable using memcpy(): I changed it to: My aim was to avo ...
The following Rust code: use std::mem; fn main() { #[derive(Debug)] #[repr(C)] struct Test { y: f32, x: u32, } le ...
I'm making some experiments with Crypto++ library, I don't understand why before that reinterpret_cast the length is 20 byte and after is only 8 chars ...
I am trying to turn a function, createArray, into a constexpr function. This function creates an array from a contiguous section in memory marked by t ...