June 11, 2009
http://d.puremagic.com/issues/show_bug.cgi?id=3057





--- Comment #10 from Brad Roberts <braddr@puremagic.com>  2009-06-11 09:47:11 PDT ---
(In reply to comment #8)
> char* str1=obj.str1;
> const char* str2=obj.str2;
> auto len1=strlen(str2);
> str1[0]=0;
> auto len2=strlen(str2);
> assert(str1!=str2,"pwnd");
> 
> GCC has stricter definition of pure function - a function whose arguments are contained in the stack (no reference types), in D this definition is extended to include immutable reference types, because they effectively behave as value types.

That's fine.  That's not a violation of purity as D has defined it.  Purity is defined, roughly, as:

  1) does not mutate global state
  2) does not depend on global state

or:
  Depends only on it's inputs and mutates only its output.

strlen is a classic example of a pure function.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
June 23, 2009
http://d.puremagic.com/issues/show_bug.cgi?id=3057





--- Comment #11 from Sobirari Muhomori <maxmo@pochta.ru>  2009-06-23 05:33:46 PDT ---
Reference type is an example of global state in the sense that it can change unexpectedly. Dependency on global state is impure because it prevents reordering of function calls and caching function results. My example demonstrates, why strlen calls can't be reordered or cached, which proves its impurity.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
June 23, 2009
http://d.puremagic.com/issues/show_bug.cgi?id=3057





--- Comment #12 from Sobirari Muhomori <maxmo@pochta.ru>  2009-06-23 05:47:40 PDT ---
strlen is a classic example of a pure function because classic strings are immutable which is not the case for C strings and strlen.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
October 10, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=3057


Alex Rønne Petersen <alex@lycus.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |alex@lycus.org
         Resolution|                            |FIXED


--- Comment #13 from Alex Rønne Petersen <alex@lycus.org> 2012-10-10 03:35:57 CEST ---
I sent a pull request a while back that added safety, purity, and nothrow annotations throughout core.stdc (not having noticed the patch here). I'll close this, but if it turns out I forgot some annotations, please reopen.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
1 2
Next ›   Last »