Hello. This is a minimal abstraction of a part of my program:
int func(string s)
{
static int [] i = [5, 6, 7];
return i[2];
}
template temp(string s) { enum temp = func(s); }
void main() { static assert(temp!"str" == 7); }
With the above code I get:
(4): Error: static variable i cannot
Why do you declare mutable constants?
On Friday, 22 January 2016 at 09:56:27 UTC, Shriramana Sharma
wrote:
In C/C++ the `static` here is used to avoid the array being
created every time the function is entered; in D too it does
the same thing, no? So if I have an array of constants in a
function that I need to be accessible to a
On Friday, 22 January 2016 at 10:15:19 UTC, Mike Parker wrote:
A static variable is still a runtime variable. It's effectively
the same as declaring a variable outside of the function scope
at module scope, except that it's visible only in the current
scope and the function name gets mangled
On 22.01.2016 10:56, Shriramana Sharma wrote:
Do all values which need to
be readable at compile time need to be declared `immutable`?
Yes, `static immutable` or `enum`.
In C/C++ the `static` here is used to avoid the array being created every
time the function is entered; in D too it does
Thanks to all who replied.
anonymous wrote:
>> Do all values which need to
>> be readable at compile time need to be declared `immutable`?
>
> Yes, `static immutable` or `enum`.
It would seem that in the case of arrays, the former is preferable to the
latter, as per the para above this header:
On 22.01.2016 15:33, Shriramana Sharma wrote:
It would seem that in the case of arrays, the former is preferable to the
latter, as per the para above this header:
http://ddili.org/ders/d.en/const_and_immutable.html#ix_const_and_immutable.variable,
%20immutable
The link doesn't work for me,