|
-
December 26th, 2002, 04:55 AM
#1
On assignment to a function pointer
Hi,
I have a the following declarations in my C code:
PHP Code:
void func1(void); // Prototype of function func1()
long *p = ... // pointer to long which contains a valid address.
// The address is that of the function func1()
void (*fptr)(void); // This is the function pointer
This address in 'p' is, as stated above, the address of the function func1().
How do I assign from pointer 'p' to pointer 'fptr' so that the
function executes if called as given below:
Thanks in advance.
-
December 26th, 2002, 05:13 AM
#2
Just do fptr = p
That will of course give a warning or two, unless you cast it: fptr = (void (*)(void))p.
I don't know why you need to store the func address in 'p' when you can assign fptr directly: fptr = func1. That's better coding style.
Good luck.
-
December 26th, 2002, 06:46 AM
#3
Re: Function pointer
Hi j0nas,
Thanks for the reply. It really helped.
The code in the posting is a curtailed version of the original
code where I had the doubt.
In the actual code, I am getting a pointer as long * (from
another part of the application) containing the function's
address. I need to execute that function from this address.
Thanks again for your help.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|