By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,260 Members | 1,468 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,260 IT Pros & Developers. It's quick & easy.

FENV_ACCESS and "pure" functions

P: n/a
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/
Nov 14 '05 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.