Functions that return the same result
when called with the same arguments
A function that always returns the same result when called
with the same arguments, and does not change any global data, is
referred to as a pure function.
By definition, it is sufficient to evaluate any particular
call to a pure function only once. Because the result of a call
to the function is guaranteed to be the same for any identical call,
each subsequent call to the function in code can be replaced with
the result of the original call.
Using the keyword __pure when declaring a function
indicates that the function is a pure function.
By definition, pure functions cannot have side effects. For
example, a pure function cannot read or write global state by using
global variables or indirecting through pointers, because accessing global
state can violate the rule that the function must return the same
value each time when called twice with the same parameters. Therefore,
you must use __pure carefully in your programs.
Where functions can be declared __pure, however,
the compiler can often perform powerful optimizations, such as Common
Subexpression Eliminations (CSEs).
This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies.
ARM websites use two types of cookie: (1) those that enable the site to function and perform as required; and (2) analytical cookies which anonymously track visitors only while using the site. If you are not happy with this use of these cookies please review our Privacy Policy to learn how they can be disabled. By disabling cookies some features of the site will not work.