Compile Time Execution of Inout Parameters

Frits van Bommel fvbommel at REMwOVExCAPSs.nl
Sun Mar 4 04:41:02 PST 2007


Walter Bright wrote:
> Xinok wrote:
>> In the D 1.007 change log, it states:
>> out and inout parameters are now allowed for compile time function 
>> execution.
>>
>> Does anybody know exactly what this means? I've tried a few different 
>> things, but no luck at getting anything to compile.
> 
> The out and inout are only for functions called by compile time executed 
> functions.

When Xinok first posted that, I thought he was right; I couldn't get 
such functions to compile either. After your post I tried again and it 
worked. After some investigation, I found the difference:
---
urxae at urxae:~/tmp$ cat test.d
int bar(out int x) { x = 2; return 1; }

int foo() { int y; bar(y); return y; }

const int z = foo();

void main(){}

urxae at urxae:~/tmp$ dmd test.d
gcc test.o -o test -m32 -lphobos -lpthread -lm -Xlinker 
-L/home/urxae/opt/dmd/lib
urxae at urxae:~/tmp$ nano test.d
urxae at urxae:~/tmp$ cat test.d
void bar(out int x) { x = 2; }

int foo() { int y; bar(y); return y; }

const int z = foo();

void main(){}

urxae at urxae:~/tmp$ dmd test.d
test.d(3): Error: cannot evaluate bar(y) at compile time
test.d(5): Error: cannot evaluate foo() at compile time
---

It seems functions returning void can't be executed at compile time, 
even if they have out/inout parameters...


Reported: http://d.puremagic.com/issues/show_bug.cgi?id=1021



More information about the Digitalmars-d mailing list