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
  • I think everyone will agree with Walt Conley: CHNLTable[] is an array of pointers.
    '&CHNLTable' is equivalent to 'CHNLTable' as well as '&(CHNLTable[0])'. That is, '&CHNLTable' is a pointer to the first element of the array and it has the type 'char code**'.
    So if you want to convert it to pointer to int (for whatever reason), use 'int* myptr = (int*)&CHNLTable;'. Actually, it's all well described in K&R. Reading this book can only do good.
    Hopefully, I didn't mess up here :-))
    Regards,
    Mike

Reply
  • I think everyone will agree with Walt Conley: CHNLTable[] is an array of pointers.
    '&CHNLTable' is equivalent to 'CHNLTable' as well as '&(CHNLTable[0])'. That is, '&CHNLTable' is a pointer to the first element of the array and it has the type 'char code**'.
    So if you want to convert it to pointer to int (for whatever reason), use 'int* myptr = (int*)&CHNLTable;'. Actually, it's all well described in K&R. Reading this book can only do good.
    Hopefully, I didn't mess up here :-))
    Regards,
    Mike

Children