pure/const function attribute and memoization

Florian Weimer fweimer@redhat.com
Wed May 15 08:49:00 GMT 2013


Back when these attributes were defined, we had no inter-procedural 
analysis or other fanciness, so I suspect we didn't consider the case 
where the annotated function only behaved as if it were pure or const. 
One important case is memoization—a function which uses this technique 
writes to global memory (so that the computed result can be reused by a 
future call), but calls to it can be freely scheduled, replicated or 
removed (for const; for pure, writes to global memory have to be taken 
into account).

Is it permitted to use pure/const for such functions?  What should our 
documentation say?

-- 
Florian Weimer / Red Hat Product Security Team



More information about the Gcc mailing list