digitalmars.D.learn - Function name from function pointer
- Paul D Anderson (19/19) Apr 11 2015 Is there a way to return the name of a function (a string) from a
- Marco Leise (9/36) Apr 11 2015 Nope, that would require that fp not only contains a pointer
- Paul D Anderson (3/37) Apr 11 2015 Okay, thanks, I can see that.
- bearophile (5/7) Apr 11 2015 Perhaps creating a string[void*] AA and initializing with all the
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
Apr 11 2015
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? PaulNope, 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
Apr 11 2015
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>:Okay, thanks, I can see that. PaulIs 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? PaulNope, 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.
Apr 11 2015
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
Apr 11 2015