| |||
| Home > Compiler-specific Features > __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.