Thread overview | ||||||
---|---|---|---|---|---|---|
|
April 11, 2015 Function name from function pointer | ||||
---|---|---|---|---|
| ||||
Is there a way to return the name of a function (a string) from a pointer to that function? Function pointer example from D Reference: --- int function() fp; void test() { static int a = 7; static int foo() { return a + 3; } fp = &foo; } void bar() { test(); int i = fp(); // i is set to 10 } --- Can I get "foo" from fp? Paul |
April 11, 2015 Re: Function name from function pointer | ||||
---|---|---|---|---|
| ||||
Posted in reply to Paul D Anderson | Am Sat, 11 Apr 2015 18:28:35 +0000 schrieb "Paul D Anderson" <claude.reins@msnmail.com>: > Is there a way to return the name of a function (a string) from a pointer to that function? > > Function pointer example from D Reference: > --- > int function() fp; > > void test() > { > static int a = 7; > static int foo() { return a + 3; } > > fp = &foo; > } > > void bar() > { > test(); > int i = fp(); // i is set to 10 > } > --- > > Can I get "foo" from fp? > > Paul > > Nope, that would require that fp not only contains a pointer to the function but also a pointer to the name. That's not how it works. But continuing that thought, you could add the function's name as an additional variable and set that every time you set fp. -- Marco |
April 11, 2015 Re: Function name from function pointer | ||||
---|---|---|---|---|
| ||||
Posted in reply to Paul D Anderson | Paul D Anderson:
> Is there a way to return the name of a function (a string) from a pointer to that function?
Perhaps creating a string[void*] AA and initializing with all the function pointers you care about.
Bye,
bearophile
|
April 11, 2015 Re: Function name from function pointer | ||||
---|---|---|---|---|
| ||||
Posted in reply to Marco Leise | On Saturday, 11 April 2015 at 19:08:50 UTC, Marco Leise wrote:
> Am Sat, 11 Apr 2015 18:28:35 +0000
> schrieb "Paul D Anderson" <claude.reins@msnmail.com>:
>
>> Is there a way to return the name of a function (a string) from a pointer to that function?
>>
>> Function pointer example from D Reference:
>> ---
>> int function() fp;
>>
>> void test()
>> {
>> static int a = 7;
>> static int foo() { return a + 3; }
>>
>> fp = &foo;
>> }
>>
>> void bar()
>> {
>> test();
>> int i = fp(); // i is set to 10
>> }
>> ---
>>
>> Can I get "foo" from fp?
>>
>> Paul
>>
>>
>
> Nope, that would require that fp not only contains a pointer
> to the function but also a pointer to the name. That's not how
> it works. But continuing that thought, you could add the
> function's name as an additional variable and set that every
> time you set fp.
Okay, thanks, I can see that.
Paul
|
Copyright © 1999-2021 by the D Language Foundation