Is there a portable equivalent of gcc __attribute__ (clean)?

I am writing some code where there are a bunch of simple clean functions that are called a lot. It is absolutely safe if these functions get optimized so that they can be called less often.

I am currently using gcc as my compiler, and I am wondering if there is a portable way:

int foo(int) __attribute__ ((pure)) 

Key key information can be found here: http://www.ohse.de/uwe/articles/gcc-attributes.html#func-pure

How can I implement something like this if the pure keyword is not available?

+6
c ++ gcc portability
source share
3 answers
 #ifdef __GNUC__ #define __pure __attribute__((pure)) #else #define __pure #endif 

Use __pure when you need it

+5
source share

No no.

+7
source share

I think the portable way is to inline functions and hope that the compiler will figure out the rest.

+1
source share

All Articles