Re: Meaning of const variables

2016-06-21 Thread H. S. Teoh via Digitalmars-d-learn
On Tue, Jun 21, 2016 at 01:48:27PM +, jmh530 via Digitalmars-d-learn wrote: [...] > Thanks to you and the others for the detailed clarifications. I think > part of the difficulty is that there are basically three things being > discussed that are all very similar: an alias to data, a pointer

Re: Meaning of const variables

2016-06-21 Thread jmh530 via Digitalmars-d-learn
On Tuesday, 21 June 2016 at 15:21:01 UTC, Ali Çehreli wrote: [snip] Thanks.

Re: Meaning of const variables

2016-06-21 Thread Ali Çehreli via Digitalmars-d-learn
On 06/21/2016 06:48 AM, jmh530 wrote: > So an immutable pointer guarantees that whatever it is pointing to will > never change, Yes but saying "_requires_ that data never changes" is more correct. When it comes to a pointer (i.e. the user of data), "guarantee" is related to const. > but a

Re: Meaning of const variables

2016-06-21 Thread jmh530 via Digitalmars-d-learn
On Tuesday, 21 June 2016 at 02:54:06 UTC, ketmar wrote: Thanks to you and the others for the detailed clarifications. I think part of the difficulty is that there are basically three things being discussed that are all very similar: an alias to data, a pointer to data, and a view of data.

Re: Meaning of const variables

2016-06-21 Thread Mike Parker via Digitalmars-d-learn
behavior is identical. And really, if you never need to take the address of the variable, then a manifest constant using enum would be more appropriate. Actually, I should say it *may* be more appropriate. Definitely only when the initializer is known at compile time. There are cases when

Re: Meaning of const variables

2016-06-20 Thread H. S. Teoh via Digitalmars-d-learn
On Tue, Jun 21, 2016 at 02:24:03AM +, jmh530 via Digitalmars-d-learn wrote: > I feel like I have a reasonable understanding of when to use const as > a parameter in a function or for const member functions. However, I > don't really understand why/when it should be used as a type modifier. >

Re: Meaning of const variables

2016-06-20 Thread ketmar via Digitalmars-d-learn
On Tuesday, 21 June 2016 at 02:24:03 UTC, jmh530 wrote: So the line from the spec is "Const types are like immutable types, except that const forms a read-only view of data. Other aliases to that same data may change it at any time." I tried making an alias of a const variable and modifying

Meaning of const variables

2016-06-20 Thread jmh530 via Digitalmars-d-learn
I feel like I have a reasonable understanding of when to use const as a parameter in a function or for const member functions. However, I don't really understand why/when it should be used as a type modifier. For instance, the Programming in D book basically just says