dlang.org/spec/function.html#pure-functions example

Paul phshaffer at gmail.com
Thu Oct 12 19:33:32 UTC 2023


The spec doc has the following statement and corresponding 
example:
***"Pure functions cannot directly access global or static 
mutable state."***

```d
int x;
immutable int y;

pure int foo(int i)
{
     i++;     // ok, modifying local state
     //x = i; // error, modifying global state
     //i = x; // error, reading mutable global state
     i = y;   // ok, reading immutable global state
     throw new Exception("failed"); // ok
}
```
If **int x** is global mutable state, what does static mutable 
state look like?


More information about the Digitalmars-d-learn mailing list