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

C51 Compiler, 8051 Utilities manuals' examples syntax for 'code' conflict

User's guide, 01.97, C compiler C51 on page 63 'explicitly defined memory types' recommends a syntax.

The Utilities guide, 04.95, page 119, has a different syntax in files c_mess0.c, c_mess1.c.

the utilities guide contradicts the recommendation in the user's guide.

Yet the 'preferred' method in the C51 compiler will NOT work. You must use the 'obsolete' method of the Utilities guide.

(1) Please explain.

(2) What is correct syntax for:
const unsigned char code *MyArray[NumberFruits] = {"apple,"banana","cherry"};

Parents
  • >Andrew Neil wrote:

    >A definition of the form

    >code int code *var
    
    >is a pointer located in code memort
    >which points to an int located in code
    >memory.



    This work, but this is obsolete syntax,
    supplied just for compatibility with old versions of C51.

    I think, good style is:

    Exapmle_1:
    int code * code ptr;
    

    In common:
    VAR_TYPE MEMORY_TYPE VAR_NAME;
    
    In Example_1:
    // VAR_NAME     - "ptr"
    // MEMORY_TYPE - "code"
    // VAR_TYPE    - "int code * "
    //                 (pointer to int, located in 'code' memory)
    


    Example_2:

    int xdata * code ptr;
    
    // VAR_NAME     - "ptr"
    // MEMORY_TYPE - "code"
    // VAR_TYPE    - "int xdata * "
    //                 (pointer to int, located in 'xdata' memory)
    




    In other words, MEMORY_TYPE keyword (code,data,bdata,xdata,pdata) should be placed just before variable name.


    Last example:
    char code * xdata * data ptr;
    
    // Read from right to left:
    //
    // 'ptr' (located in 'data' memory) is a pointer to
    // (located in 'xdata' memory) pointer to
    // (located in 'code'  memory) 'char'
    


Reply
  • >Andrew Neil wrote:

    >A definition of the form

    >code int code *var
    
    >is a pointer located in code memort
    >which points to an int located in code
    >memory.



    This work, but this is obsolete syntax,
    supplied just for compatibility with old versions of C51.

    I think, good style is:

    Exapmle_1:
    int code * code ptr;
    

    In common:
    VAR_TYPE MEMORY_TYPE VAR_NAME;
    
    In Example_1:
    // VAR_NAME     - "ptr"
    // MEMORY_TYPE - "code"
    // VAR_TYPE    - "int code * "
    //                 (pointer to int, located in 'code' memory)
    


    Example_2:

    int xdata * code ptr;
    
    // VAR_NAME     - "ptr"
    // MEMORY_TYPE - "code"
    // VAR_TYPE    - "int xdata * "
    //                 (pointer to int, located in 'xdata' memory)
    




    In other words, MEMORY_TYPE keyword (code,data,bdata,xdata,pdata) should be placed just before variable name.


    Last example:
    char code * xdata * data ptr;
    
    // Read from right to left:
    //
    // 'ptr' (located in 'data' memory) is a pointer to
    // (located in 'xdata' memory) pointer to
    // (located in 'code'  memory) 'char'
    


Children
No data