I've been implemening Annex F in my compiler, and one issue to do with "pure"
functions has come to my attention.
The compiler has for a long time had a __pure keyword (and a related pragma
form), which can be used to indicate that a function is "pure", ie has no
side-effects and always returns the same result for given arguments.
Now, pretty much all the functions in <math.h> are "pure" by that definition,
when invoked from code with #pragma STDC FENV_ACCESS OFF (and if they don't
set errno). But they're not when FENV_ACCESS is ON. I'm pondering what
mechanism I can use to signal this. I don't really want to leave the <math.h>
functions untagged, given that they're the majority of the potentially pure
functions in the standard library.
I know that many other compilers have some sort of analogue of the __pure
keyword to aid optimisation, so I'd be interested to know if anyone else has
thought about this.
Two obvious possibilities are
1) an alternative keyword, eg __purefp, which would mean "pure unless
FENV_ACCESS ON".
2) ignore the __pure keyword altogether when FENV_ACCESS is ON.
Any thoughts? If there's a precedent here, I don't want to go off on my own.
--
Kevin Bracey, Principal Software Engineer
Tematic Ltd Tel: +44 (0) 1223 503464
182-190 Newmarket Road Fax: +44 (0) 1223 503458
Cambridge, CB5 8HE, United Kingdom WWW: http://www.tematic.com/