[PATCH] Make attribute functions pure

Robert Dewar dewar@gnat.com
Mon Jul 26 01:11:00 GMT 2004


Laurent GUERBY wrote:

> I find the RM 10.2.1 (18) pretty clear, what makes you
> think there's room for interpretation? As written
> it explicitely allows the programmer to cheat
> in Pure functions (memoizing) without the compiler
> playing strange games.

You always have to remember that *all* the rules in the
RM are as-if semantics. So you are allowed any optimization
which does not affect the semantics. Now if a pure function
is really pure in the sense of having no side effects, all
sorts of transformations are semantically neutral, moving
the call, adding calls, etc.

As I said in my previous message, the original intention
was that pure functions should not be able to have side
effects. So the original intention is that all these
transformations would be valid.

The fact that by marginal and somewhat peculiar fiddling
you can get pure functions with side effects was to some
extent unintended, and my guess is that the ARG would
decide that the possibility of side effects should not
limit the range of allowable transformations.

Interpreting the RM is not an easy task, and if you have
never followed ARG discussions closely you might be
surprised :-)

> May be an additional pragma with other semantics
> would be more appropriate.

I don't think so.




More information about the Gcc-patches mailing list