Calling function by direct address

A

aleksa

Google found this:
void (* const JMP_IRAM2) (void) = (void (*) (void)) 0x300000;

that works, but also generates a pointer (pointing to 0x300000),
which is not even used by the generated code.

Just curious, is there a way that doesn't make an unnecessary pointer?
 
J

Jens Thoms Toerring

aleksa said:
Google found this:
void (* const JMP_IRAM2) (void) = (void (*) (void)) 0x300000;
that works, but also generates a pointer (pointing to 0x300000),
which is not even used by the generated code.
Just curious, is there a way that doesn't make an unnecessary pointer?

If you just want to call the function at the address

( ( void ( * ) ( void ) ) 0x300000 )( );

will do the job (assuming that there's a callable function
with that signature at that address and that an integer con-
stant can be converted to a function pointer).

Regards, Jens
 
N

Nobody

Google found this:
void (* const JMP_IRAM2) (void) = (void (*) (void)) 0x300000;

that works, but also generates a pointer (pointing to 0x300000),
which is not even used by the generated code.

Just curious, is there a way that doesn't make an unnecessary pointer?

Jens reply is probably what you want, but ... did you try using "static"?

Without it, the compiler has to assume that other compilation units
may reference JMP_IRAM2, so it has to allocate storage and add an entry to
the symbol table.
 
A

aleksa

Jens reply is probably what you want, but ... did you try using "static"?

Without it, the compiler has to assume that other compilation units
may reference JMP_IRAM2, so it has to allocate storage and add an entry to
the symbol table.

You are right, "static" does remove the pointer. Thanks.
 
A

aleksa

If whoever provides this entry point is not providing a C header file to call
it, are you sure it is safe to call from C? C functions conform to a particular
calling sequence that non-C entry points might not. Also on some systems a
function pointers contain a code pointer and data pointer. I would make my
intention clear by using assembly code to call a non-C entry point.

If you know with complete certainity that the entry point does conform toC
calling conventions, there's a simpler way on practically every system: declare
the function as a usual extern function, and then use a loader directive to
define the entry point to your desired address.

--
Damn the living - It's a lovely life.           I'm whoever youwant me to be.
Silver silverware - Where is the love?       At least I can stay incharacter.
Oval swimming pool - Where is the love?    Annoying Usenet one post at a time.
Damn the living - It's a lovely life.         And introducing...Tubular Bells.

Ah, so there are a million ways of doing this :)

That should be the best solution, really. I'll try it.
Thanks.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,952
Messages
2,570,111
Members
46,695
Latest member
Juliane58C

Latest Threads

Top