digitalmars.D - in vs. const
- dsimcha (6/6) Mar 07 2009 All the discussion about const on this NG lately has made me realize tha...
- Sean Kelly (4/10) Mar 07 2009 There's no difference between them. The 'in' version just happens to be...
- Adam Burton (18/29) Mar 07 2009 I have not done any D2, but surely 'in' is modifiable in the function lo...
- Robert Fraser (2/37) Mar 07 2009 No it's not. "in" means "const scope" in D2 (and scope is a NOP right no...
- Sergey Gromov (3/41) Mar 08 2009 Closures are not allocated for delegates passed as scope arguments so
- Sergey Gromov (8/16) Mar 07 2009 In D1, there are no const types, so the first form doesn't compile. In
- Kagamin (2/4) Mar 09 2009 How can it be scope? If you have scope object, it gets *destructed* when...
- Denis Koroskin (2/7) Mar 09 2009 No. Scope has different meaning here. For example, delegates don't cause...
- Kagamin (2/3) Mar 09 2009 O RLY? That's good news.
All the discussion about const on this NG lately has made me realize that I have no idea what the difference is between const and in, i.e. what is the difference between: SomeType foo(const SomeType bar) and SomeType foo(in SomeType bar) ?
Mar 07 2009
dsimcha wrote:All the discussion about const on this NG lately has made me realize that I have no idea what the difference is between const and in, i.e. what is the difference between: SomeType foo(const SomeType bar) and SomeType foo(in SomeType bar)There's no difference between them. The 'in' version just happens to be D1-compatible, and its meaning could be more easily changed over time if any tweaking is necessary (unlikely).
Mar 07 2009
Sean Kelly wrote:dsimcha wrote:I have not done any D2, but surely 'in' is modifiable in the function locally where as const is not (so since const is not modifiable at all it implies in). For example: void myfunc(in int i) { i = 10; // i is changed to 10, k stays as 12 } int k = 12; myfunc(k); ================================= void myfunc(const int i) { i = 10; // Fails to compile as i is const } in k = 12; myfunc(k);All the discussion about const on this NG lately has made me realize that I have no idea what the difference is between const and in, i.e. what is the difference between: SomeType foo(const SomeType bar) and SomeType foo(in SomeType bar)There's no difference between them. The 'in' version just happens to be D1-compatible, and its meaning could be more easily changed over time if any tweaking is necessary (unlikely).
Mar 07 2009
Adam Burton wrote:Sean Kelly wrote:No it's not. "in" means "const scope" in D2 (and scope is a NOP right now).dsimcha wrote:I have not done any D2, but surely 'in' is modifiable in the function locally where as const is not (so since const is not modifiable at all it implies in). For example: void myfunc(in int i) { i = 10; // i is changed to 10, k stays as 12 } int k = 12; myfunc(k); ================================= void myfunc(const int i) { i = 10; // Fails to compile as i is const } in k = 12; myfunc(k);All the discussion about const on this NG lately has made me realize that I have no idea what the difference is between const and in, i.e. what is the difference between: SomeType foo(const SomeType bar) and SomeType foo(in SomeType bar)There's no difference between them. The 'in' version just happens to be D1-compatible, and its meaning could be more easily changed over time if any tweaking is necessary (unlikely).
Mar 07 2009
Sat, 07 Mar 2009 17:43:19 -0800, Robert Fraser wrote:Adam Burton wrote:Closures are not allocated for delegates passed as scope arguments so scope is far from NOP.Sean Kelly wrote:No it's not. "in" means "const scope" in D2 (and scope is a NOP right now).dsimcha wrote:I have not done any D2, but surely 'in' is modifiable in the function locally where as const is not (so since const is not modifiable at all it implies in). For example: void myfunc(in int i) { i = 10; // i is changed to 10, k stays as 12 } int k = 12; myfunc(k); ================================= void myfunc(const int i) { i = 10; // Fails to compile as i is const } in k = 12; myfunc(k);All the discussion about const on this NG lately has made me realize that I have no idea what the difference is between const and in, i.e. what is the difference between: SomeType foo(const SomeType bar) and SomeType foo(in SomeType bar)There's no difference between them. The 'in' version just happens to be D1-compatible, and its meaning could be more easily changed over time if any tweaking is necessary (unlikely).
Mar 08 2009
Sat, 7 Mar 2009 15:37:07 +0000 (UTC), dsimcha wrote:All the discussion about const on this NG lately has made me realize that I have no idea what the difference is between const and in, i.e. what is the difference between: SomeType foo(const SomeType bar) and SomeType foo(in SomeType bar) ?In D1, there are no const types, so the first form doesn't compile. In the second form 'in' is redundant, it means the default behavior and may be omitted without consequences. In D2, 'in' means 'const scope'. I've seen that in writing but can't remember where. Therefore clever people use 'in' to mean 'const' in D2 and NOP in D1 to improve portability.
Mar 07 2009
Sergey Gromov Wrote:In D2, 'in' means 'const scope'. I've seen that in writing but can't remember where.How can it be scope? If you have scope object, it gets *destructed* when leaving scope: when function exits. Ouch.
Mar 09 2009
On Mon, 09 Mar 2009 18:07:05 +0300, Kagamin <spam here.lot> wrote:Sergey Gromov Wrote:No. Scope has different meaning here. For example, delegates don't cause heap allocation when passed as scope parameters in D2.In D2, 'in' means 'const scope'. I've seen that in writing but can't remember where.How can it be scope? If you have scope object, it gets *destructed* when leaving scope: when function exits. Ouch.
Mar 09 2009
Denis Koroskin Wrote:No. Scope has different meaning here.O RLY? That's good news.
Mar 09 2009