Hacker News new | ask | show | jobs
by gpderetta 720 days ago
You can set fast math (or a subset of it) on a translation unit basis.
3 comments

Because the language works by textual inclusion and so a "translation unit" isn't really just your code this is much more likely to result in nasty surprises, up to and including ODR violations.
Yes, if you try hard enough I'm sure you can find ways to screw up.

From a practical point of view it is fine.

That's not really true. If you link a shared library that was compiled with -ffast-math, that will affect the entire program. https://moyix.blogspot.com/2022/09/someones-been-messing-wit...
To enable this "feature" I believe you have to specify fast math while linking the .so, it is not enough to do it when compiling.

It had also been fixed recent GCC versions.

Or even on a per function basis, at least with gcc (no clue about clang...)
In principle yes, you can use Attribute optimize, but I wouldn't rely on it. Too many bugs open against it.
It's worked for me in the past but maybe I got lucky.