3 ms·
From the C abstract machine's perspective it is undefined: 1. To substract the two function pointers after casting to BYTE*. 2. To read the bytes through thos
by leni536 5y ago
From the C abstract machine's perspective it is undefined:
1. To substract the two function pointers after casting to BYTE*.
2. To read the bytes through those pointers.
3. To cast the copied bytes back to function and invoke it.
The article only focuses on 3, and only about how it's undefined because the compiler is not required to generate position independent code. But an optimizing compiler in theory can just optimize the whole function away from looking at the very first undefined line.
The message is that yes, you need to step out of the standard to do stuff like this, but you may have to consult a lot more about your implementation defined behavior than you originally signed up for.