RE: Adding const to java

"Patrick Piche" <ppiche@cae.com>
7 Nov 2002 00:52:35 -0500

          From comp.compilers

Related articles
RE: Adding const to java ppiche@cae.com (Patrick Piche) (2002-11-07)
| List of all articles for this month |
From: "Patrick Piche" <ppiche@cae.com>
Newsgroups: comp.compilers
Date: 7 Nov 2002 00:52:35 -0500
Organization: Compilers Central
Keywords: Java
Posted-Date: 07 Nov 2002 00:52:35 EST

> Constant modifier is helpful in determining pure
> functions i.e. call with the same arguments are always
> results in the same value. So compiler can remove
> later calls in the context and use the first one's
> results.


> a = f.const_p();
> b = f.const_p(); // can be safely replaced by b = a


No, const functions can only guarantee that the object
on which the method is called will not be modified (f in your
example). The function could still have side effects (such
as printing to console) which would make it a non-pure function
(preventing your optimisation to be performed).


Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.