I was reading online and someone suggested doing something along the following lines (this is a simplified example of the mechanic, not a real-world example):
I want to know whether this is considered a safe operation, and why it works.
What is the pointer p pointing at, and why do I have to take the address of the pointer before I can dereference it?
As a follow-up I'm interested by the implications of a similar method in terms of function pointers, but first I need to understand what's happening here, whether it's safe, portable, etc.
#include <iostream>
int main()
{
int a = 5;
int b = 10;
void *p = reinterpret_cast<void*>(a * B)/>;
int result = *reinterpret_cast<int*>(&p);
std::cout << std::endl << result << std::endl;
return 0;
}
I want to know whether this is considered a safe operation, and why it works.
What is the pointer p pointing at, and why do I have to take the address of the pointer before I can dereference it?
As a follow-up I'm interested by the implications of a similar method in terms of function pointers, but first I need to understand what's happening here, whether it's safe, portable, etc.