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

pointer to code memory

hello every one

i am trying to create a pointer to two dimensional character array located in code space of 8051

i am getting a warning of c182:pointer to different objects

my code is like this

unsigned char code table[120][5]={some values}//array daclaration

unsigned char code **ptr;//pointer to code memory

ptr = table;//trying to access this way

can any one tell what is the mistake in it

thanks®ards
ganesh

Parents
  • You've fallen prey to the common misconception that pointers and arrays are fully interchangeable in C. They're not.

    In particular, a pointer to an array of a multi-dimensional array is not constructed as a pointer-to-pointer-...to-element.

    Correct code (setting aside the additional complication of the "code" keyword) would be any of

    unsigned char (*ptr_to_whole_array)[120][5] = &table;
    unsignec char (*ptr_to_first_row)[5] = table;
    unsigned char *ptr_to_element = table[0];
    

Reply
  • You've fallen prey to the common misconception that pointers and arrays are fully interchangeable in C. They're not.

    In particular, a pointer to an array of a multi-dimensional array is not constructed as a pointer-to-pointer-...to-element.

    Correct code (setting aside the additional complication of the "code" keyword) would be any of

    unsigned char (*ptr_to_whole_array)[120][5] = &table;
    unsignec char (*ptr_to_first_row)[5] = table;
    unsigned char *ptr_to_element = table[0];
    

Children