Run-time setting of immutable variable?

DLearner bmqazwsx123 at gmail.com
Thu Sep 2 16:01:19 UTC 2021


Suppose there is a variable that is set once per run, and is 
(supposed) never to be altered again.  However, the value to 
which it is set is not known at compile time.
Example below, variable is 'ArrPtr';
```
ubyte[10] Arr;

// immutable void* ArrPtr;
void* ArrPtr;

void main() {

    ArrPtr = cast(void*)Arr[0];

// <Lots of code depending on ArrPtr, but not supposed to modify 
ArrPtr>

}
```
Is there a way of getting D to guarantee that ArrPtr is never 
modified after
```
    ArrPtr = cast(void*)Arr[0];
```

Best regards


More information about the Digitalmars-d-learn mailing list