Call a function with a function pointer

Dicebot public at dicebot.lv
Fri Oct 11 08:58:04 PDT 2013


On Friday, 11 October 2013 at 15:55:17 UTC, Artur Skawina wrote:
> It's probably not just "incompetence" (the compiler is able to 
> figure this
> out in other contexts), but a deliberate choice. Having 
> function types
> depend on their bodies would not be a good idea. Eg
>
>     int c;
>     auto f() {
>        int a = 42;
>        int f1() { return a; }
>        int f2() { return 0; }
>        return !c?&f1:&f2;
>     }
>
> Mark f2 as 'static' and this code will no longer compile. If 
> that would
> be done automatically then you'd have to 'undo' it manually, 
> which would
> cause even more problems (consider generic code, which isn't 
> prepared
> to handle this).
>
> artur
>
> [1] at least without other language improvements; enabling 
> overloading on
>     'static', plus a few other enhancements, would change the 
> picture.

Agreed.

However, I do feel uncomfortable with new habit to put `static` 
everywhere to avoid hidden compiler "help" :(


More information about the Digitalmars-d-learn mailing list