-
How to execute function
Hi, this question is suitable to micro controller programming. I have a function and fix its location at some particular address in linker file. Now i want to execute this function on particular condition. How to do it? I am thinking of using function pointers like
Code:
Void (*fctptr) (void).
Can i assign an address to this fctptr same as the address of the function in linker file like fctptr = (void *)8000.
Any help? This is the typical application of bootloader.
-
Given this
void (*fctptr) (void);
You call it with
fctptr();
> Can i assign an address to this fctptr same as the address of the function in linker file like fctptr = (void *)8000.
Yeah, you should be able to.
-
my confusion is if i a pointer is pointing to unsigned char like
then we type cast it to unsigned char and assign to p like for example
Code:
p = (unsigned char *)0x100;
but in the case of function pointers how should i type cast like for exampe
and if i am trying to assign any address how should i typecast? can i do simply as below?
Code:
fptr = (void *)1000;
For everything can i simply use (void *)?
-
A function pointer cast looks like this.
Code:
#include <stdio.h>
int main ( ) {
int (*fp)(void);
fp = (int(*)(void))100;
if ( fp() ) {
}
return 0;
}
-
Now i Understand, Thanks.