0 Members and 1 Guest are viewing this topic.
Don't no too much about C, but I read that it explicitly doesn't allow such things.
So here I am thinking about an idea... And it turns out my idea already has a name, "Threaded Code"!My question is, is there any C/C++ legal way to jump to an address? A computed Goto if you will...goto *someaddress;
Yes, something like this should workvoid (*app)() = (void(*))0x123456;and then laterapp();I can't test this right now, but I'm pretty sure the above would jump to addres 0x123456.
No, that's a function pointer which will invoke the calling convention (saving registers etc) which would add a lot of overhead a threaded code Virtual Machine...
The most obvious legal way to do this is to use a table of function pointers.
Well the gcc extension is as portable as gcc is. If you keep your dubious computed branch target code to just one translation unit, you could always make it an exception in your makefile and have everything else all nice and ANSI.
Oh, then I misunderstood your question. :-)
#ifdef ARMasm { /* whatever */}#elseasm { /* x86 equivalent */}#endif
If you're just writing for ARM and testing on x86, couldn't you use a conditionally-compiled bit of assembler like:Code: [Select]#ifdef ARMasm { /* whatever */}#elseasm { /* x86 equivalent */}#endifor somesuch?
Not really, your advice was good, I didn't provide enough specification for you! As Karlos has also pointed out function pointers are the legal way to do this... I just don't want to save the registers for every function call!