3 ms·
"pure" and "const" are GCC function attributes which are supposed to help the optimizer. Confusingly enough "const" demands a higher level of purity than "pure"
by copx 14y ago
"pure" and "const" are GCC function attributes which are supposed to help the optimizer. Confusingly enough "const" demands a higher level of purity than "pure"..
I would never use those attributes except - maybe - in the most critical loops and then only with a big "WARNING!!!" sign. Why? GCC does not / cannot enforce the guarantees given by "const" and "pure" yet the optimizer always assumes they are true. I.e. accidentally reduce the purity of a function decorated in this way.. and you might create very hard to find bugs.
This is a general problem in C and C++, those languages simply weren't designed to enforce such contracts. C99's "restrict" has the same problem.