iOS Developer Tip: Catch Floating Point or Pointer Bugs

After spending the last 3 days hunting for a bug, I think I have to share the little tip that saved me from throwing my Mac out of the window.

When in despair, add this option to “Other CFlags” in your project’s settings:

    -fcatch-undefined-behavior

With that turned on, all behaviours undefined on ARM will be tracked down: divisions by 0, non aligned memory access, right shift on signed integers or, in my case, calling acos with a value a very little over 1.0f (due to rounding errors in float point arithmetics).

Do not keep it in release mode as it adds a lot of extra checks to the generated code.

This saved my day, really.

I’m a consultant and developer for Mobile, Web, Games and Apps projects. I co-founded Fovea 8 years ago.

Tagged with: , ,
Posted in Blog