pure functions
I have read certain articles that encourage to use/write
pure functions (if possible) as they are better suited for
optimization.
I got one example that expalins how the code can be optimised.
For eg:
__pure int square(int x)
{
return x * x;
}
int f(int n)
{
return square(n) + square(n);
}
The function f() can be optimised to call pure function square() once.
Is there any other way pure functions help in optimization ?
Is the pure function itself produce much optimized code as compared
to non pure functions ?
.
Relevant Pages
- Re: pure functions
... That would depend highly on the compiler, and imho, such a compiler would have an overly simplistic implementation. ... pure functions as they are better suited for optimization. ... Is the pure function itself produce much optimized code as compared ... (comp.lang.c) - Re: pure functions
... I hear some people even say that efficiency considerations are ... important factors for acceptance of new features into the C language. ... Wouldn't discussing opportunities for optimization ... > Pure functions aren't part of C. ... (comp.lang.c) - Re: pure functions
... >Is there any other way pure functions help in optimization? ... Optimization is much less efficient if there are any "side effects" ... C compiler has to clean up to that "as if" state before the side ... of using a different algorithm -- there has been more than one ... (comp.lang.c) - Re: pure functions
... pure functions as they are better suited for optimization. ... I got one example that expalins how the code can be optimised. ... of evaluations. ... (comp.lang.c) - pure functions
... __pure int square ... Is there any other way pure functions help in optimization? ... Is the pure function itself produce much optimized code as compared ... (comp.lang.c) |
|