MISRA Discussion Forums
Casting a Float to a Signed Integer - Printable Version

+- MISRA Discussion Forums (https://forum.misra.org.uk)
+-- Forum: MISRA C (https://forum.misra.org.uk/forumdisplay.php?fid=4)
+--- Forum: MISRA-C: 2004 rules (https://forum.misra.org.uk/forumdisplay.php?fid=17)
+---- Forum: 6.10 Arithmetic Type Conversions (https://forum.misra.org.uk/forumdisplay.php?fid=37)
+---- Thread: Casting a Float to a Signed Integer (/showthread.php?tid=346)



Casting a Float to a Signed Integer - embedded.kyle - 05-03-2007

I'm working with some legacy code and part of my job is to modify it to comply with the MISRA standard. A large portion of the code relies on macros such as this one:

[code]#define CURRENT_LARGE_SHIFT (18L)
#define CURRENT_LARGE_SCALE(v) (int32_t)(v * (1L


- misra-c - 09-05-2007

The use of macros which are evaluated with multiple types is to be discouraged.

We do not see an easy solution and cannot provide specific advice.

Generally, we would suggest that the macro is replaced with a solution for each specific type.