This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Write platform independent code.

Hi Fellow STudents of software archeticture,

I am writing an program for one application in C / C++ which should run on all target controller architecture like 8051 , AVR, PIC , MSP430 or ARM7 and any other. How could I write this Platform Independent Code. Where is the platform.hpp in KEIL CX51 and ARM compilers.

can anyone help me on this.

  • Wherever you put it! (you have to write it, first).

    Note that Keil C51 and CX51 are not C++ compilers.

  • Sorry, but microcontrollers are not like PC machines, or POSIX environments where you can just move the source code - and sometimes binary - to a different machine.

    You will have to write a low-level driver layer for the processor-specific features that you need. And the rest of the code will have to be written without assumptions to size of int, sign of char, byte order, availability of bit variables, order and align of bit fields, ...

    Note that to get good performance on so diverse platforms as 8051 and ARM, you will have to rely on clever use of data types, compiler support for inline functions, and #defines.

    But exacly what was the requirements for your school assignment? To point at differences between different architectures, and ways to overcome them? How to overcome them in an efficient way? To write a program that can be compiled for a number of target processors? Anything else?

  • write generic stuff in strict ANSI C.
    make a solid distinction between implementation details (hardware...) and general functionality.