Thread overview | |||||
---|---|---|---|---|---|
|
February 17, 2007 odd issue in 1.006 | ||||
---|---|---|---|---|
| ||||
In 1.006, this seems to be allowed in a CTFE function: int q = A[i..j].length; c += q; But not this: c += A[i..j].length; Kevin |
February 17, 2007 Re: odd issue in 1.006 | ||||
---|---|---|---|---|
| ||||
Posted in reply to Kevin Bealer | Kevin Bealer wrote:
> In 1.006, this seems to be allowed in a CTFE function:
>
> int q = A[i..j].length;
> c += q;
>
> But not this:
>
> c += A[i..j].length;
Both should work. Can you provide a complete example?
|
February 17, 2007 Re: odd issue in 1.006 | ||||
---|---|---|---|---|
| ||||
Posted in reply to Walter Bright | Walter Bright wrote:
> Kevin Bealer wrote:
>> In 1.006, this seems to be allowed in a CTFE function:
>>
>> int q = A[i..j].length;
>> c += q;
>>
>> But not this:
>>
>> c += A[i..j].length;
>
> Both should work. Can you provide a complete example?
Sure; in the 'bar' function below, the 'v += A.length' fails, but the previous two lines work just fine as a replacement. The failure is reported like this:
dmd -ofexa example.d
example.d(26): Error: cannot evaluate (bar)("a b c d") at compile time
Kevin
// -*- c++ -*-
import std.stdio;
import std.string;
import std.file;
// For DMD 1.006
int bar(char[] A)
{
int v;
for(int i = 0; i < A.length; i++) {
if (A[i] != ' ') {
// int q = A.length; // these work
// v += q;
v += A.length; // but this fails
}
}
return v;
}
int main(char[][] args)
{
const int foo = bar("a b c d");
return 0;
}
|
Copyright © 1999-2021 by the D Language Foundation