Date: Sat, 27 May 2023 02:55:43 +0500
>> I know that it is not possible to create objects out of thins air:
>>
>> int i = = 42;
>> char buffer[sizeof(int)];
>> std::memcpy(buffer, &i, sizeof(int));
>>
>> int* j = reinterpret_cast<int*>(buffer);
>> *j; // UB, even if *j == i, as j does not point to an int object
>
> This is not accurate since implicit object creation has been introduced.
reinterpret_cast<int*>(buffer) still points at buffer[0]
>>
>> int i = = 42;
>> char buffer[sizeof(int)];
>> std::memcpy(buffer, &i, sizeof(int));
>>
>> int* j = reinterpret_cast<int*>(buffer);
>> *j; // UB, even if *j == i, as j does not point to an int object
>
> This is not accurate since implicit object creation has been introduced.
reinterpret_cast<int*>(buffer) still points at buffer[0]
Received on 2023-05-26 21:55:49