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

ANSI-C and idata

Hi All,

I need to make portable ANSI-C code, any advice how easier to hide "idata"? I use small memory model, and wouldn't change it.

Regards,
Vladimir

  • Write your code with something like the following typedefs and macros, and redefine them appropriately for each compiler you use:

    typedef unsigned char               U8;
    typedef unsigned short              U16;
    typedef unsigned long               U32;
    typedef struct { U8 byte[8]; }      U64;
    
    typedef signed char                 S8;
    typedef signed short                S16;
    typedef signed long                 S32;
    typedef struct { U8 byte[8]; }      S64;
    
    typedef unsigned char  Bool;
    
    /// fast, probably small data RAM
    #define FAST  data
    /// large, probably slower, data RAM
    #define BULK  xdata
    /// data beyond the normal range of data RAM
    #define FAR   far
    // program store
    #define CODE  code
    
    #define REENTRANT reentrant
    

    I use different include files for different platforms. Many people use one include file with a series of #if <compiler ID symboL> in them, each wrapped around a set of definitions like the above.

    For an ANSI compiler, you'd just #define FAST/FAR/CODE/REENTRANT, etc., to expand to nothing. Adjust the integer typedefs to fit your compiler (especially if you already have a "long long").

    The syntax of some compiler extensions may not let you find a place for these keywords. Sometimes you need to turn them into macros that can completely rewrite a function prototype or variable declaration. Setting an interrupt handler, for example, is often done by making a function call instead of an "interrupt" keyword.

  • Thank you for your answers!

    Best Regards,
    Vladimir