digitalmars.D - Compile Time Execution of Inout Parameters
- Xinok (5/5) Mar 04 2007 In the D 1.007 change log, it states:
- Walter Bright (3/9) Mar 04 2007 The out and inout are only for functions called by compile time executed...
- Frits van Bommel (26/36) Mar 04 2007 When Xinok first posted that, I thought he was right; I couldn't get
- Walter Bright (5/7) Mar 04 2007 This is by design:
- Frits van Bommel (5/14) Mar 04 2007 This just seems to be a pretty arbitrary restriction. I'm not saying I'd...
- Bill Baxter (7/17) Mar 04 2007 That seems kind of arbitrary. The first thought that came to mind was
- Xinok (10/11) Mar 04 2007 executed functions.
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.
Mar 04 2007
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.
Mar 04 2007
Walter Bright wrote:Xinok wrote: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 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 urxae:~/tmp$ dmd test.d gcc test.o -o test -m32 -lphobos -lpthread -lm -Xlinker -L/home/urxae/opt/dmd/lib urxae urxae:~/tmp$ nano test.d urxae 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 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=1021In 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.
Mar 04 2007
Frits van Bommel wrote:It seems functions returning void can't be executed at compile time, even if they have out/inout parameters...This is by design: 1) functions with no output make no sense evaluating at compile time 2) it makes no sense to have a compile time function return its value via an out or inout rather than the return value
Mar 04 2007
Walter Bright wrote:Frits van Bommel wrote:agreed.It seems functions returning void can't be executed at compile time, even if they have out/inout parameters...This is by design: 1) functions with no output make no sense evaluating at compile time2) it makes no sense to have a compile time function return its value via an out or inout rather than the return valueThis just seems to be a pretty arbitrary restriction. I'm not saying I'd use it for anything other than testing if it works, but I don't see any technical reason to forbid it either...
Mar 04 2007
Walter Bright wrote:Frits van Bommel wrote:That seems kind of arbitrary. The first thought that came to mind was what if you need to return two values? For instance a min-max function that returns both the minimum and maximum value. In that case it would be weird to arbitrarily pick one as the "real" return value and make the other an out parameter. --bbIt seems functions returning void can't be executed at compile time, even if they have out/inout parameters...This is by design: 1) functions with no output make no sense evaluating at compile time 2) it makes no sense to have a compile time function return its value via an out or inout rather than the return value
Mar 04 2007
The out and inout are only for functions called by compile timeexecuted functions. I figured that much. Frits cleared it up though, it was because I had no return type that the compiler was restricting me from compiling it. I think this is one restriction which should be lifted, or at least modified to allow functions with out / inout parameters. I believe restrictions should only be put in place in a language if it prevents something dangerous, such as returning the address of a local variable, or using an uninitalized variable. This is one restriction which doesn't prevent anything dangerous, and is just something which programmers will be forced to work around.
Mar 04 2007