public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* a question about const and pure functions.
@ 2004-11-10 19:14 Kenneth Zadeck
  2004-11-10 23:35 ` Geoffrey Keating
  0 siblings, 1 reply; 20+ messages in thread
From: Kenneth Zadeck @ 2004-11-10 19:14 UTC (permalink / raw)
  To: GCC Mailing List, Geoffrey Keating, Novillo, Diego, Berlin, Daniel

Do we mark functions being const or pure (TREE_READONLY or DECL_IS_PURE) 
based on some external standard definition or are these defined any way 
that the gcc community feels is good?  

I am in the process of moving the code that does this analysis so that 
it is done very early and at once for the entire compilation unit.  
There appear to be a few minor bugs in the code as well as a few missed 
opportinities.  But before I was going to make any changes, I was 
wondering if there was any better standard of definition beyond what is 
defined in doc/extend.texi.

Kenny

^ permalink raw reply	[flat|nested] 20+ messages in thread
* Re: a question about const and pure functions.
@ 2004-11-11 15:09 Richard Kenner
  2004-11-11 15:26 ` Steven Bosscher
  0 siblings, 1 reply; 20+ messages in thread
From: Richard Kenner @ 2004-11-11 15:09 UTC (permalink / raw)
  To: roger; +Cc: gcc

    A "const" call has no side-effects and its results depend purely on the
    values of its arguments.  This closely follows the mathematical notion
    of a "function".  A "pure" call has no side-effects, but in addition to
    it's arguments may depend upon the memory/global variables of the system.

"The devil is in the details", as they say!  Is memoization considered
a "side-effect", for example?  What about a function passed a pointer and
which indirectly modifies that point?  Is that a "side-effect"?  It's
very tricky to get definitions exactly right.

^ permalink raw reply	[flat|nested] 20+ messages in thread
* Re: a question about const and pure functions.
@ 2004-11-11 15:45 Richard Kenner
  0 siblings, 0 replies; 20+ messages in thread
From: Richard Kenner @ 2004-11-11 15:45 UTC (permalink / raw)
  To: stevenb; +Cc: gcc

    So write it down.

You have to agree on them first!  At least one language standardization
committee spent many hours on the question of pure and memoization.

    But your example is obvious - if the function is passed a pointer and
    it modifies it, that is clearly a side-effect because it is a a change
    that cannot be seen directly from the caller's side.

I agree that it should be considered a side-effect, but that makes the
definition of "side-effect" a little harder to state.

^ permalink raw reply	[flat|nested] 20+ messages in thread

end of thread, other threads:[~2004-11-25 12:44 UTC | newest]

Thread overview: 20+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-11-10 19:14 a question about const and pure functions Kenneth Zadeck
2004-11-10 23:35 ` Geoffrey Keating
2004-11-11 15:04   ` Kenneth Zadeck
2004-11-11 15:07     ` Roger Sayle
2004-11-11 15:17       ` Daniel Berlin
2004-11-11 15:17       ` Daniel Berlin
2004-11-11 17:20       ` Geert Bosch
2004-11-11 17:45         ` Roger Sayle
2004-11-11 19:04       ` Tom Tromey
2004-11-11 19:17         ` Roger Sayle
2004-11-11 19:31           ` Tom Tromey
2004-11-11 19:38             ` Roger Sayle
2004-11-11 20:15               ` Diego Novillo
2004-11-11 21:40     ` Geoffrey Keating
2004-11-12 14:50       ` Kenneth Zadeck
2004-11-12 23:19       ` Geert Bosch
2004-11-25 13:22     ` Jan Hubicka
2004-11-11 15:09 Richard Kenner
2004-11-11 15:26 ` Steven Bosscher
2004-11-11 15:45 Richard Kenner

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).