3 ms·
GCC's pure and const function attributes pretty much allow for these optimizations.
by _pmf_ 13y ago
GCC's pure and const function attributes pretty much allow for these optimizations.
- _delirium 13y agoFor scalar types I agree, but now that I think of it, I'm not sure it's even possible to write array code using them, unless I'm missing something. If you can't modify the array in-place or write to a provided "output" parameter, and you can't malloc a fresh array to return (because that's a side effect), how do you write a pure function of type int[] -> int[] at all? The nice thing about Haskell is that it conceptually mallocs a fresh array to return, but then optimizes away the intermediate array in a lot of cases.
- cpeterso 13y agoI believe GCC's pure and const function attributes, like the restrict keyword, are only advisory and have no extra compile-time checks that your functions are actually pure or const.