Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Is MISRA C the answer to migration problems when cross compiling
#1
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
<t></t>
Reply
#2
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
<t>This post is made in a personal capacity<br/>
Member of MISRA-C-WG since 2002</t>
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)