To help LDC/GDC

kenji hara k.hara.pg at gmail.com
Thu Apr 11 03:27:39 PDT 2013


2013/4/11 John Colvin <john.loughran.colvin at gmail.com>

> On Thursday, 11 April 2013 at 10:03:39 UTC, deadalnix wrote:
>
>> On Thursday, 11 April 2013 at 08:36:13 UTC, Joseph Rushton Wakeling wrote:
>>
>>> On 04/10/2013 08:39 PM, Walter Bright wrote:
>>>
>>>> Sure there is. Declare the function as pure, and the function's
>>>> parameters as
>>>> const or immutable.
>>>>
>>>
>>> Sure, I accept that.  What I was meaning, though, was an up-front
>>> declaration
>>> which would make the compiler shout if those necessary conditions were
>>> not met.
>>>
>>> i.e.
>>>
>>>       pure foo(int n) { ... }     // compiles
>>>
>>>       strong pure bar(int n) { ... } // compiler instructs you to make
>>>                                      // variables const or immutable
>>>
>>
>> Both are strongly pure.
>>
>
> is foo strongly pure because of n being a value type that cannot contain
> any indirection? (i.e. as far as the outside world is concerned you don't
> get any side effects whatever you do with it).
>
> Is the same for structs that contain no indirection? Or do they have to be
> const/immutable?
>

It is same for structs that has no *mutable* indirections. In below, all
functions are strongly pure.

module x;
struct S1 { int n; }
struct S2 { immutable int[] arr; }
struct S3 { int[] arr; }

pure int foo0(int n);
pure int foo1(S1);   // S1 has no indirections
pure int foo2(S2);   // S2 has no *mutable* indirections
pure int foo3(immutable ref S3 x);   // foo3 cannot access any mutable
indirections

Kenji Hara
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.puremagic.com/pipermail/digitalmars-d/attachments/20130411/ddc2ff38/attachment-0001.html>


More information about the Digitalmars-d mailing list