On Sunday, 24 May 2015 at 17:35:39 UTC, Jay Norwood wrote:
I'm a bit confused by the documentation of the ctfe limitations wrt static arrays due to these seemingly conflicting statements, and the examples didn't seem to clear anything up. I was wondering if anyone has examples of clever things that might be done with static arrays and pointers using ctfe.

2.Executed expressions may not reference any global or local static variables.

C-style semantics on pointer arithmetic are strictly enforced. Pointer arithmetic is permitted only on pointers which point to static or dynamic array elements.

"Static array" has a special meaning. It does not mean "static variable with an array type". Static arrays are those of the form Type[size]. That is, the size is known statically.

Examples:

1) static int[5] x; -- x is a static variable with a static array type
2) static int[] x; -- static variable, dynamic array
3) int[5] x; -- non-static variable, static array
4) int[] x; -- non-static variable, dynamic array

So, CTFE can't handle examples 1 and 2, because they're static variables. 3 and 4 are fine.

Reply via email to