10.46 __attribute__((pure)) function attribute

Many functions have no effects except to return a value, and their return value depends only on the parameters and global variables. Functions of this kind can be subject to data flow analysis and might be eliminated.


This function attribute is a GNU compiler extension that the ARM compiler supports.

Although related, this function attribute is not equivalent to the __pure keyword. The function attribute equivalent to __pure is __attribute__((const)).


int Function_Attributes_pure_0(int b) __attribute__((pure));
int Function_Attributes_pure_0(int b)
    return b++;
int foo(int b)
    int aLocal=0;
    aLocal += Function_Attributes_pure_0(b);
    aLocal += Function_Attributes_pure_0(b);
    return 0;

The call to Function_Attributes_pure_0 in this example might be eliminated because its result is not used.

Related concepts
5.17 Functions that return the same result when called with the same arguments
Related reference
10.33 __attribute__((const)) function attribute
Non-Confidential PDF file icon PDF version ARM DUI0472J
Copyright © 2010-2013 ARM. All rights reserved.