4.3.3. __attribute__((const))

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 is supported by the ARM compiler. It has the keyword equivalent __pure.


int Function_Attributes_const_0(int b) __attribute__ ((const));

int Function_Attributes_const_2(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.

See also

Copyright © 2007, 2010 ARM Limited. All rights reserved.ARM DUI 0348A