www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - odd issue in 1.006

reply Kevin Bealer <kevinbealer gmail.com> writes:
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
Feb 17 2007
parent reply Walter Bright <newshound digitalmars.com> writes:
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?
Feb 17 2007
parent Kevin Bealer <kevinbealer gmail.com> writes:
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; }
Feb 17 2007