How really pure should a pure function be?
Bonzini
bonzini@gnu.org
Wed Feb 13 09:53:00 GMT 2002
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
More information about the Gcc
mailing list