FENV_ACCESS and "pure" functions

K

Kevin Bracey

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

Forum statistics

Threads
473,774
Messages
2,569,599
Members
45,175
Latest member
Vinay Kumar_ Nevatia
Top