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

C182 error kicking my butt

Hopefully this makes sense. I've cut down the actual code to make this short.

I have a series of strings as shown:


char code Num1[] =  {"One  "};
char code Num2[] =  {"Two  "};
char code Num3[] =  {"Three"};


I then have an array of pointers that have all the address of the start of those strings:

code char code *CHNLTable[] = { Num1, Num2, Num3};


I then have a pointer in a function that I want to assign to an element in the array and I get a C182 "Pointer to different objects" warning.

void func(void){	
  unsigned int *myptr;
   myptr = &CHNLTable;

   ...code that uses myptr

}

I don't understand the warning AND the code seems to work fine. Can someone explain to me the dumb thing I'm doing??

Parents
  • Oops - sorry, you're right!

    char code Num1[] =  {"One  "};
    char code Num2[] =  {"Two  "};
    char code Num3[] =  {"Three"};
    
    code char code *CHNLTable[] = { Num1, Num2, Num3};
    
    void func(void){	
      unsigned int *myptr;
       myptr = &CHNLTable;
    
       ...code that uses myptr
    }

    But you have still defined CHNLTable to be a table of pointers to chars, whereas myptr is a pointer to int - a "different object".

    Just because C51's internal representation of a memory-specific pointer happens to be the same as its internal representation of an int doesn't mean to say that a memory-specific pointer is the same as an int!

    Does that make sense this time?

Reply
  • Oops - sorry, you're right!

    char code Num1[] =  {"One  "};
    char code Num2[] =  {"Two  "};
    char code Num3[] =  {"Three"};
    
    code char code *CHNLTable[] = { Num1, Num2, Num3};
    
    void func(void){	
      unsigned int *myptr;
       myptr = &CHNLTable;
    
       ...code that uses myptr
    }

    But you have still defined CHNLTable to be a table of pointers to chars, whereas myptr is a pointer to int - a "different object".

    Just because C51's internal representation of a memory-specific pointer happens to be the same as its internal representation of an int doesn't mean to say that a memory-specific pointer is the same as an int!

    Does that make sense this time?

Children
No data