digitalmars.D.learn - Declaring variables const vs immutable
- Brother Bill (13/13) Nov 09 When declaring a variable, we may add const or immutable to its
- Steven Schveighoffer (4/6) Nov 09 My answer from before:
- Brother Bill (3/9) Nov 09 Thank you. I missed that you had already covered this question.
When declaring a variable, we may add const or immutable to its type. ``` const int a = 86; // typeof(a).stringof is const(int) immutable int b = 99; // typeof(b).stringof is immutable(int) const int[] array_a = [42, 100]; // typeof(array_a).stringof is const(int[]) immutable int[] array_b = [42, 100]; // typeof(array_b).stringof is immutable(int[]) ``` They seem to have identical behavior, at least in the simple case. My question is how does D treat these types differently? When should one pick one vs. the other?
Nov 09
On Sunday, 9 November 2025 at 23:17:44 UTC, Brother Bill wrote:My question is how does D treat these types differently? When should one pick one vs. the other?My answer from before: https://forum.dlang.org/post/wkrdjxxkjzrtwqzmwijx forum.dlang.org -Steve
Nov 09
On Monday, 10 November 2025 at 04:47:44 UTC, Steven Schveighoffer wrote:On Sunday, 9 November 2025 at 23:17:44 UTC, Brother Bill wrote:Thank you. I missed that you had already covered this question.My question is how does D treat these types differently? When should one pick one vs. the other?My answer from before: https://forum.dlang.org/post/wkrdjxxkjzrtwqzmwijx forum.dlang.org -Steve
Nov 09








Brother Bill <brotherbill mail.com>