betterC question
Basile B.
b2.temp at gmx.com
Thu Nov 19 13:16:43 UTC 2020
On Thursday, 19 November 2020 at 00:07:12 UTC, Dibyendu Majumdar
wrote:
> I have simple test program:
>
> import core.stdc.stdio : printf;
>
> void test() {
> int* a;
> printf("a == null %d\n", a == null);
> }
>
> int function() fp = test;
>
> extern (C) void main() {
> fp();
> }
>
> Why do I get:
>
> \d\dmd-2.092.1\windows\bin64\dmd.exe -betterC tests.d
> tests.d(5): Error: printf cannot be interpreted at compile
> time, because it has no available source code
>
> This is on Windows
IMO another problem here is that `function` and `delegate` are
special cases of the `*` postfix. With a syntax like
int()* fp = test
it would be more obvious to new comers that `&` is missing.
This is a syntax I experiment in STYX for example [1].
Note that then there's also the problem with functions pointers
requiring a context. This context is not necessarily a `this`
(for closures it's a frame obviously).
[1]
https://gitlab.com/basile.b/styx/-/blob/master/tests/backend/function_pointers.sx#L10
More information about the Digitalmars-d-learn
mailing list