10.33 __attribute__((const)) function attribute

Many functions examine only the arguments passed to them, and have no effects except for the return value. This is a much stricter class than __attribute__((pure)), because a function is not permitted to read global memory. If a function is known to operate only on its arguments then it can be subject to common sub-expression elimination and loop optimizations.


This function attribute is a GNU compiler extension that the ARM compiler supports. It has the keyword equivalent __pure.


int Function_Attributes_const_0(int b) __attribute__((const));
int Function_Attributes_const_0(int b)
    int aLocal=0;
    aLocal += Function_Attributes_const_0(b);
    aLocal += Function_Attributes_const_0(b);
    return aLocal;

In this code Function_Attributes_const_0 might be called once only, with the result being doubled to obtain the correct return value.

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