This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
How really pure should a pure function be?
- From: "Bonzini" <bonzini at gnu dot org>
- To: <gcc at gcc dot gnu dot org>
- Date: Wed, 13 Feb 2002 18:16:11 +0100
- Subject: How really pure should a pure function be?
I found two definitions in the GCC manual:
1) must depend only on global variables and parameters
2) can be called fewer times than specified
These are partly in conflict, because what about a function that interns a
string and, hence, modifies global variables once and nevertheless always
returns the same value with the same string? This in general satisfies
requisite 2 so I could define it as pure if I don't care if GCC removes a
call that is not assigned anywhere. On a scale from 1 to 10, how much am I
looking for trouble?
Also, if I got the difference between const and pure right, in practice pure
can be subject to CSE and const to loop optimizations as well. Is this a
good rule of thumb?
Paolo