Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a portable equivalent of gcc's __attribute__ (pure)?

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?

like image 651
shuttle87 Avatar asked Sep 30 '10 05:09

shuttle87


2 Answers

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.

like image 69
Justin Avatar answered Oct 21 '22 15:10

Justin


No, there is not.

like image 41
wilx Avatar answered Oct 21 '22 16:10

wilx