On Thursday, 2 September 2021 at 23:12:28 UTC, Steven
Schveighoffer wrote:
[...]
immutable means "I can never change and *everything I point at*
can never change".
[...]
If that is how the language defines the keyword 'immutable' when
used in the definition of a pointer variable, then so be
On 9/2/21 9:01 AM, DLearner wrote:
Suppose there is a variable that is set once per run, and is (supposed)
never to be altered again.
An accessor function can be a solution, which supports your other
comment about data potentially mutating by other means:
// Assume these are in a module
// v
On 9/2/21 1:17 PM, DLearner wrote:
I am looking for a mutable Arr but would like an immutable ArrPtr.
Then you want const not immutable.
Here is the reason:
```d
void main()
{
int x = 5;
immutable int *ptr = cast(immutable int *)&x;
assert(*ptr == 5); // ok
x = 6;
assert(
On Thu, Sep 02, 2021 at 05:17:15PM +, DLearner via Digitalmars-d-learn
wrote:
[...]
> The following clean-compiled and produced the expected result:
> ```
> ubyte[10] Arr;
>
> immutable void* ArrPtr;
> shared static this() {
> ArrPtr = cast(immutable void*)(&Arr[0]
On Thursday, 2 September 2021 at 17:17:15 UTC, DLearner wrote:
Surely there is no inconsistency - at run time the array is in
a fixed place, so ArrPtr is (or at least should be) a
constant, but the contents of the array
can vary as the program runs.
In the case of `immutable(T)* ArrPtr`, the
If you want only address, you can keep it as size_t:
ubyte[10] Arr;
immutable size_t Address;
static this() {
Address = cast(size_t)(&Arr[0]);
}
On Thursday, 2 September 2021 at 16:46:46 UTC, Steven
Schveighoffer wrote:
On 9/2/21 12:01 PM, DLearner wrote:
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,
On 9/2/21 12:01 PM, DLearner wrote:
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* A
On Thu, Sep 02, 2021 at 04:01:19PM +, DLearner via Digitalmars-d-learn
wrote:
> 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.
This is the classic use case of `immutabl
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 = ca
10 matches
Mail list logo