__attribute__((const)) is a GCC attribution to check purity of the function execution.
I think this is being supported on Clang, but when I put this to a method, it doesn’t seem to work.
@interface C1
- (id)method1 __attribute__((const));
@end
int a = 0;
@implementation C1
- (id)method1 __attribute__((const))
{
a++;
return nil;
}
@end
The code above doesn’t generate any warning or error.
Is this attribution working on Clang? Or what should I do to make this to work?
The
constattribute doesn’t check the purity of the function. It declares the purity of the function, so the optimizer can eliminate calls to the function. It’s up to you to actually make sure the function is pure.