4.1.12. __pure

The __pure keyword asserts that a function declaration is pure.

A function is pure only if:

__pure is a function qualifier. It affects the type of a function.

Note

This keyword has the function attribute equivalent __attribute__((const)).

Default

By default, functions are assumed to be impure.

Usage

Pure functions are candidates for common subexpression elimination.

Restrictions

A function that is declared as pure can have no side effects. For example, pure functions:

  • cannot call impure functions

  • cannot use global variables or dereference pointers, because the compiler assumes that the function does not access memory, except stack memory

  • must return the same value each time when called twice with the same parameters.

Example

int factr(int n) __pure
{
    int f = 1;

    while (n > 0)
        f *= n--;
    return f;}

See also

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