| |||||||||||||||||||||
On-Line Manuals RealView Compiler User's Guide | __pure
A pure function is a function that always returns the same result if it is called with the same arguments. By default, 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. This is an instance of the compiler optimization known as Common Subexpression Elimination (CSE). To instruct the compiler that a function is pure, declare the function as The use of the The first routine shows a naive implementation of the function Table 4.7. C code for pure and impure functions
Table 4.8 shows the corresponding disassembly of the machine code produced by the compiler for each of the sample implementations of Table 4.7, where the C code for each implementation has been compiled using the option Table 4.8. Disassembly for pure and impure functions
In the disassembly of the 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 See __pure in the Compiler Reference Guide for more information about pure functions. | ||||||||||||||||||||
| |||||||||||||||||||||