I'm writing some code where there are a bunch of simple pure functions that get called a lot. It's perfectly safe if these functions get get optimized to be called less often.
Currently I am using gcc as my compiler and I'm wondering if there is a portable way of doing:
int foo(int) __attribute__ ((pure))
Info about the pure keyword can be found here: http://www.ohse.de/uwe/articles/gcc-attributes.html#func-pure
How would I go about implementing something like this if the pure keyword is not available?
Since C++11, you can use the standardized attribute syntax with GCC specific attributes:
[[gnu::pure]]
int foo(int)
Since C++17, this is guaranteed to be fine on any compiler, since if they don't recognize [[gnu::pure]]
, they must ignore it without error.
No, there is not.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With