How to make sure no floating point code is used

How to make sure no floating point code is used

Source Node: 2539608

Float and double data types area a bad choice for embedded applications. At least in most applications, and can or should be avoided, even with hardware FPU support present. The MCU on Eclipse blog looks at the process.

Floating point operations or float and double data types are something I avoid in embedded applications: in most cases float and double data types are not necessary and only cause precision and code size and performance issues. Even with an FPU present it is problematic. Another good read is here: https://www.embedded.com/floating-point-data-in-embedded-software/

The article describes how to configure the GNU toolchain, so that no float or double operations are used, with the example of ARM Cortex-M. What I do? ‘Poisoning’ (!!!) the source code, forcing the gcc compiler to use software floating point operations and then catch them with the GNU linker.

Poison the float and double

One easy way is to ‘poison’ any float or double usage, using a pragma:

#pragma GCC poison float double

After the ‘poison’ keyword I specify a list of identifiers which are not allowed after the occurrence of the poison pragma, resulting in a compiler error.

See a detailed explanation in the post here.

Time Stamp:

More from Ada Fruit