I want the program to jump to a specific address in memory and continue execution from that address. I thought about using goto
but I don\'t have a label rather
#include
#include
void go(unsigned int addr) {
(&addr)[-1] = addr;
}
int sub() {
static int i;
if(i++ < 10) printf("Hello %d\n", i);
else exit(0);
go((unsigned int)sub);
}
int main() {
sub();
}
Of course, this invokes undefined behavior, is platform-dependent, assumes that code addresses are the same size as int
, etc, etc.