Вот код, который я написал для экспериментов с 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?
}
Во-первых, почему такое reinterpret_cast
преобразование разрешено? Я думал, что такое преобразование плохо сформировано.
reinterpret_cast
для приведения одного типа к другому (возможно, несовместимому), многие скажут, что вы заслуживаете того, что получаете. - person Some programmer dude   schedule 05.08.2014