I have following program
int a = 216;
bool* v = (bool*)((void*)&a);
std::cout << (*v == true) << endl;
I would expect this program to print out true or false but instead it prints out 216. I have compiled it with g++ (Ubuntu 4.8.2-19ubuntu1) 4.8.2
. Is it expected behaviour or some bug? Why would equality operator return different type than bool?
--------- EDIT ---------
My intention is not to cast to void but to make v storing 216 in its memory location. Alternative program may look like this:
bool v;
int a = 216;
memcpy(&v, &a, sizeof(bool));
std::cout << (v == true) << endl;
Or I can take uninitialized bool pointer which points to some random value which happens to be e.g. 216.