Jay wrote on 27 August 2008 09:55: > Yeah that's probably ok. > Volatile is enough to force the ordering?
Absolutely; it's a defined part of the standard that all volatile side-effects must complete in-order. GCC will not move code past a volatile operation. > I still like just not caching mask. I think that's the best solution also. > Is "volatile*" legal or just pseudo? Legal. See the language in the standard about it being the qualification of the type of the lvalue through which you load or store that makes it a volatile operation. > Some platforms cache neither. > Are some platforms getpagesize slow and others fast? > Or it's just "random evolution"? > If it's just "random", and nobody knows getpagesize to be slow, > I'd say just never cache either. I have no idea if anyone's measured it or not, but if we only cache size, not mask, then it's completely robust and it's a trivial optimisation that can't hurt. I certainly can't see that a subtract-by-one-and-not operation would ever take so long as to be worth saving the time by caching the result. cheers, DaveK -- Can't think of a witty .sigline today....