There is the code that I've written for experiments with reinterpret_cast<T>
#include <iostream>
#include <cstdlib>
using std::cout;
using std::endl;
int foo()
{
cout << "foo" << endl;
return 0;
}
void (*bar)();
int main()
{
bar = reinterpret_cast<void (*)()>(foo); //Convertion a function type to a pointer to function type
bar(); //displays foo. Is it UB?
}
First of all why such reinterpret_cast convertion permitted? I thought such conversion is ill-formed.
reinterpret_castto cast one type to another (possibly incompatible) type many would say that you deserve what you get.