[Issue 8185] Pure functions and pointers

d-bugmail at puremagic.com d-bugmail at puremagic.com
Sun Jun 3 12:44:35 PDT 2012


http://d.puremagic.com/issues/show_bug.cgi?id=8185



--- Comment #12 from art.08.09 at gmail.com 2012-06-03 12:46:28 PDT ---
(In reply to comment #11)
> Pointers may only access their own memory blocks, therefore exactly those
> blocks participate in argument value and return value.

What does 'their own memory block' mean? The problem is a pointer is basically
an unbounded array, and, if the access isn't restricted somehow, makes the
function dependent on global memory state.

> But why does it even matter? Isn't this discussion mostly philosophical?

The compiler will happily assume that template functions are pure even when
they clearly are not, and there isn't even a way to mark such functions as
"impure" (w/o using hacks like calling dummy functions etc).
Example - a function that is designed to operate on arrays, will always be
called with a pointer to inside an array, and can assume that the previous and
next element is always valid: 

  f4(T)(T* p) {
      p[-1] += p[0];
   }

The compiler thinks f4() is pure, when it clearly is not; optimizations based
on that assumption are likely to result in corrupted data.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------


More information about the Digitalmars-d-bugs mailing list