468,784 Members | 1,561 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,784 developers. It's quick & easy.

How to Return Function Pointer's Memory Address?

I set Function Pointer variable to private so unauthorized users cannot
access it, but they are allowed to use Get_ and Set_ functions to modify
Function Pointer variable. Look at my example.

unsigned char foo(void)
{
return 0xC1;
}

unsigned char (*pfoo)(void) = foo;

unsigned char* Get_foo(void)
{
// return pfoo; // Error -- can't return function pointer
return unsigned char (*pfoo)(void); // Error -- can't return function
pointer
}

Can you please correct Get_foo() function?

Bryan Parkoff
Sep 1 '05 #1
2 2901
Ben
Bryan Parkoff wrote:
I set Function Pointer variable to private so unauthorized users cannot
access it, but they are allowed to use Get_ and Set_ functions to modify
Function Pointer variable. Look at my example.

unsigned char foo(void)
{
return 0xC1;
}

unsigned char (*pfoo)(void) = foo;

unsigned char* Get_foo(void)
{
// return pfoo; // Error -- can't return function pointer
return unsigned char (*pfoo)(void); // Error -- can't return function
pointer
}

Can you please correct Get_foo() function?


Take a look here:

http://www.newty.de/fpt/fpt.html#r_value

Ben
--
I'm not just a number. To many, I'm known as a String...
Sep 1 '05 #2
Bryan Parkoff wrote:
I set Function Pointer variable to private so unauthorized users cannot
access it, but they are allowed to use Get_ and Set_ functions to modify
Function Pointer variable. Look at my example.

unsigned char foo(void)
Bad habit.
unsigned char foo()
{
return 0xC1;
}

unsigned char (*pfoo)(void) = foo;
unsigned char(*pfoo)() = foo;
unsigned char* Get_foo(void)
unsigned char(*)() Get_Foo()
{
// return pfoo; // Error -- can't return function pointer
return unsigned char (*pfoo)(void); // Error -- can't return function
pointer
}

Can you please correct Get_foo() function?

Sure.

The above works. But it is easier to write:
unsigned char foo()
{
return 0xC1;
}

typedef unsigned char (*pfoo_type)();

pfoo_type pfoo = foo;

pfoo_type Get_Foo()
{
return pfoo;
}

Gabriel
Sep 1 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Pushker Pradhan | last post: by
4 posts views Thread by Isaac | last post: by
8 posts views Thread by M. Moennigmann | last post: by
23 posts views Thread by Nascimento | last post: by
42 posts views Thread by Martin Jørgensen | last post: by
57 posts views Thread by Robert Seacord | last post: by
4 posts views Thread by | last post: by
4 posts views Thread by Immortal_Nephi | last post: by
1 post views Thread by CARIGAR | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.