3

We are developing application level code that runs on an ARM processor. The BSP (low level code) is being delivered by a 3d party so our code sits just on top of this abstraction layer (code is written in c++).

To do unit testing, I assume we will have to mock/stub out the BSP library(essentially abstracting out the HW), but what I'm not sure of is if I write/run the unit test on my pc, do I compile it with for example GCC? Normally we use Realview compiler to compile our code for the ARM. Can I assume that if I compile and run the code with x86 compiler and the unit tests pass that it will also pass when compiled with RealView compiler?

I'm not sure how much difference the compiler makes and if you can trust that if the x86 compiled code pass the unit tests that you can also be confident that the Realview compiled code is ok.

2

Although compilers contain bugs just like any other piece of software, the chances that you encounter one of those bugs while creating your own software are close to zero and the chance that such a bug manifests itself as misbehaving software is even smaller.

Apart from compiler bugs, you could get different behavior because the two compilers interpret your code differently. As long as you stay away from the murky corners of the language and especially avoid using undefined or unspecified behavior or non-portable assumptions (such as the size of basic types), then all C++ compilers are actually very good at producing consistent behavior when compiling the same code with different compilers.

In general, unless you are doing something very special, if your code compiles with all the relevant compilers then you can be sure that the produced executables also show consistent behavior with each other.

  • Different optimization algoritms are possible used in the compilers. With armcc beeing "the compiler producing the best and smallest code for ARM" it's unlikely it will be the same as GCC. Possibly different libc is also used, since glibc isn't suited for embedded. – iveqy Nov 7 '13 at 10:02
  • @iveqy: You are right that different compilers will not produce identical binaries and I didn't claim that. But for a well-defined C++ application, the different optimizations may not affect the observable behavior of the program (except for the timing, which is not considered observable by C++) – Bart van Ingen Schenau Nov 7 '13 at 10:10
  • I guess it depends what you mean with "the observable behavior of the program" for me it is the assembly instructions, since we are talking about an embedded system it's even more important to know what your compiler actually are doing (I mean, there must be one reason for @NomadAlien to use armcc instead of gcc). Also again, glibc and the RealView libc differs. And RealView also has an other linker. So no, he can't trust the x86 code with gcc to behave with armcc on an arm cpu. – iveqy Nov 7 '13 at 11:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.