3 ms·
They are a promise and that is precisely what makes them powerful. It gives GCC info it might not be able to derive, but you know to be true. You can even prom
by dmitrygr 7y ago
They are a promise and that is precisely what makes them powerful. It gives GCC info it might not be able to derive, but you know to be true.
You can even promise a func is pure without even implementing it in the same translation unit! That produces lots of improvement. See these two godbolt links:
https://godbolt.org/z/v2zqJI https://godbolt.org/z/v2zqJI
https://godbolt.org/z/kk3Q3T https://godbolt.org/z/kk3Q3T
- einpoklum 7y ago> You can even promise a func is pure without even implementing it in the same translation unit! Actually that's the main point, as if it's in the same TU, the compiler can probably figure out a function is pure.
- dmitrygr 7y agooften but not always, for example a function using asm() to access, say, some AES intrinsics is pure (const even) since the output only depends on input, but oftentimes compiler by itself will not declare a function with an asm() block pure or const
- einpoklum 7y agoWell, fair point, but - compilers shouldn't be that lazy :-)