Help | Site Map
Connecting Tech Pros Worldwide
 
 
LinkBack Thread Tools
  #1  
Old September 1st, 2005, 04:45 PM
Bryan Parkoff
Guest
 
Posts: n/a
Default 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


  #2  
Old September 1st, 2005, 04:55 PM
Ben
Guest
 
Posts: n/a
Default Re: How to Return Function Pointer's Memory Address?

Bryan Parkoff wrote:[color=blue]
> 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?[/color]

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...
  #3  
Old September 1st, 2005, 04:55 PM
Gabriel
Guest
 
Posts: n/a
Default Re: How to Return Function Pointer's Memory Address?

Bryan Parkoff wrote:[color=blue]
> 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)[/color]

Bad habit.
unsigned char foo()
[color=blue]
> {
> return 0xC1;
> }
>
> unsigned char (*pfoo)(void) = foo;[/color]

unsigned char(*pfoo)() = foo;
[color=blue]
> unsigned char* Get_foo(void)[/color]

unsigned char(*)() Get_Foo()
[color=blue]
> {
> // 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?[/color]
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
 

Bookmarks

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over network members.
Post your question now . . .
It's fast and it's free

Popular Articles