3

does anyone know of an automated way to make sure that a piece of C code doesn't use any floating point? Either compiler options, gcc, msvc, clang or some static analysis tool. I looked in the gcc compiler options and for coverity checkers, but couldn't find anything. I might have missed something. One way would be to search for the keyword 'float' in the code, but this would give many false positives in case the floating point code is disabled by a macro.

Thanks,

hko
  • 548
  • 2
  • 19
  • Unlink the FP support? – Martin James Sep 21 '17 at 19:14
  • 5
    @MartinJames How would you do that? – Eugene Sh. Sep 21 '17 at 19:17
  • 1
    I remember some trick I have seen with defining bogus types.. will try to find it. Essentially it is to redefine the unwanted types before the code section you don't want it to use. – Eugene Sh. Sep 21 '17 at 19:20
  • 2
    You could look for `float` in the source after preprocessing. Not much better, but still could be used. – HolyBlackCat Sep 21 '17 at 19:20
  • 1
    `#pragma GCC poison float` perhaps? – o11c Sep 21 '17 at 19:22
  • 1
    Or, if you're on a platform that supports `-msoft-float`, use that, but replace the library with an empty one so you'll get link errors. – o11c Sep 21 '17 at 19:24
  • 1
    [Here you go](https://stackoverflow.com/questions/30895120/what-is-bogus-type-in-c). Yet it won't prevent using FP constants, for example... – Eugene Sh. Sep 21 '17 at 19:24
  • Thanks for all the tips so far. Redefining float to a bogus name seems okay. But ideally it would be a solution that doesn't require to touch the source code. Not sure if it is possible. – hko Sep 21 '17 at 19:33

0 Answers0