MISRA Discussion Forums
Is MISRA C the answer to migration problems when cross compiling - Printable Version

+- MISRA Discussion Forums (https://forum.misra.org.uk)
+-- Forum: MISRA C (https://forum.misra.org.uk/forumdisplay.php?fid=4)
+--- Forum: General Questions (https://forum.misra.org.uk/forumdisplay.php?fid=27)
+--- Thread: Is MISRA C the answer to migration problems when cross compiling (/showthread.php?tid=1343)



Is MISRA C the answer to migration problems when cross compiling - boen - 11-05-2017

Hey

Can MISRA C be the answer to migration problems when cross compiling for an other CPU architecture?

I had a lot of trouble cross compiling C programs from X86 to ARM structure. To prevent these problems in the
future I went looking for a standard that doesn't allow or at least warns you when you program something that
might give problems when running on an other platform.

Some examples of these problems you can find here: https://msdn.microsoft.com/en-us/library/jj635841.aspx

The first problem in the example, Conversion of Floating-point to Unsigned Integer, is one I had recently myself.

Thanks


Re: Is MISRA C the answer to migration problems when cross compiling - phaedsys - 11-05-2017

The first thing you need to know is that C is NOT portable without a LOT of care. A large part of C is unspecified, undefined and implementation defined parts of C. Refer to your ISO-C language standard annex on portability issue. MISRA-C does go a long way to taming a lot of this but it is not a silver bullet and can only be part of the solution.

A lot of it depends on the compilers you are using. You will need to see the differences between them for the three categories above. This will be in the compiler documentation. Start there.

The page you linked to is for C++. C and C++ are completely different languages with a mainly similar syntax. I am not sure why it talks about converting float to a 32 bit integer. Both x86 and ARM compilers have the float type. You can use Float on ARM MCU's.

Incidentally you are not "cross compiling" but "porting" code designed for one target MCU to a different MCU. A Cross-compiler eg IAR, Keil, GHS etc is a compiler working on a host with one CPU type and compiling code to run on a different target MCU. The code is never intended to run on the host MCU/CPU