This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]