Is MISRA C the answer to migration problems when cross compiling

Questions and discussions about MISRA C not fitting under migration or rules forums

Moderators: misra-c, david ward

Post Reply
boen
Posts: 1
Joined: Thu Apr 27, 2017 9:09 am
Company: Atlas Copco

Is MISRA C the answer to migration problems when cross compiling

Post by boen » Thu May 11, 2017 12:49 pm

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

phaedsys
Posts: 50
Joined: Fri Sep 17, 2004 10:53 pm
Company: Phaedrus Systems
Location: Phaedrus Systems Tamworth, UK
Contact:

Re: Is MISRA C the answer to migration problems when cross compiling

Post by phaedsys » Thu May 11, 2017 1:06 pm

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
This post is made in a personal capacity
Member of MISRA-C-WG since 2002

Post Reply

Return to “General Questions”