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

Code portability

Hello,
I was browsing through older posts that deal with the painful issue of portability (http://www.keil.com/forum/docs/thread8109.asp). I was (and still am) a big advocate of programming as much as possible conforming to the C standard, and having a layered structure that allowed "plugging-in" other hardware. But I have come to change my mind recently. I am reading the "ARM system developer's guide" (excellent book by the way. I'm reading it because I want to port some C167 code to an ARM9 environment) in which chapter 5 discusses writing efficient C code for an ARM. The point is, and it is fairly demonstrated, that even common, innocent looking C code can either be efficient of very inefficient on an ARM depending on specific choices made, let alone another processor used! So, if we are talking about squeezing every clock cycle out of a microcontroller - I do not believe that portability without ultimately littering the code is possible!

Parents
  • Vince,
    what you write is very true, but to make code 'portable' for that laundry list would make the portability effort far exceed the effort put in the working code.

    I have been through a compiler change ot two and, in each case, said to myself, thank heaven for CodeWright.

    A port (of non-portable code) is relatively painless when you have an intelligent editor.

    However, there are some things that both make coding and porting easier such as, for example, the small example of mine below.

    Erik

                                                // pointer in data in
    #define U8DI  unsigned char   idata * data  // data       idata
    #define U8DX  unsigned char   xdata * data  // data       xdata
    #define U8IX  unsigned char   xdata * idata // idata      xdata
    #define U8XX  unsigned char   xdata * xdata // xdata      xdata
    #define U8IC  unsigned char   code  * idata // idata      code
    #define U8DC  unsigned char   code  * data  // data       code
    #define U8XC  unsigned char   code  * xdata // xdata      code
    #define U8CC  unsigned char   code  * code  // code       code
    
    #define U16DX unsigned short  xdata * data  // data       xdata
    #define U16IX unsigned short  xdata * idata // idata      xdata
    #define U16CC unsigned short  code  * code  // code       code
    #define U16DC unsigned short  xdata * data  // data       xdata
    
    #define U32DX unsigned long   xdata * data  // data       xdata
    #define U32DC unsigned long   xdata * data  // data       xdata
    

Reply
  • Vince,
    what you write is very true, but to make code 'portable' for that laundry list would make the portability effort far exceed the effort put in the working code.

    I have been through a compiler change ot two and, in each case, said to myself, thank heaven for CodeWright.

    A port (of non-portable code) is relatively painless when you have an intelligent editor.

    However, there are some things that both make coding and porting easier such as, for example, the small example of mine below.

    Erik

                                                // pointer in data in
    #define U8DI  unsigned char   idata * data  // data       idata
    #define U8DX  unsigned char   xdata * data  // data       xdata
    #define U8IX  unsigned char   xdata * idata // idata      xdata
    #define U8XX  unsigned char   xdata * xdata // xdata      xdata
    #define U8IC  unsigned char   code  * idata // idata      code
    #define U8DC  unsigned char   code  * data  // data       code
    #define U8XC  unsigned char   code  * xdata // xdata      code
    #define U8CC  unsigned char   code  * code  // code       code
    
    #define U16DX unsigned short  xdata * data  // data       xdata
    #define U16IX unsigned short  xdata * idata // idata      xdata
    #define U16CC unsigned short  code  * code  // code       code
    #define U16DC unsigned short  xdata * data  // data       xdata
    
    #define U32DX unsigned long   xdata * data  // data       xdata
    #define U32DC unsigned long   xdata * data  // data       xdata
    

Children
No data