9.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.

Note

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

Examples

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
4.16 Functions that return the same result when called with the same arguments
Related reference
9.45 __attribute__((pure)) function attribute
Non-ConfidentialPDF file icon PDF versionARM DUI0375E
Copyright © 2007, 2008, 2011, 2012, 2014 ARM. All rights reserved.