cpointersmicrocontrollerpic24

Warning in array of pointers "initialization from incompatible pointer type"


What I am asking here can be very easy to solve. Code works fine but this warning is bugging me!

//initailize array elements
    char ZeroA[6]   = {0xC0,0x07,0x40,0x04,0xC0,0x07,};
    char OneA[6]    = {0x80, 0x04, 0xC0, 0x07, 0x00, 0x04,};
    char TwoA[6]    = {0x40, 0x07, 0x40, 0x05, 0xC0, 0x05,};
    char ThreeA[6]  = {0x40, 0x05, 0x40, 0x05, 0xC0, 0x07,};
    char FourA[6]   = {0x80, 0x03, 0x00, 0x02, 0x80, 0x07,};
    char FiveA[6]   = {0xC0, 0x05, 0x40, 0x05, 0x40, 0x07,};
    char SixA[6]    = {0xC0,0x05,0x40,0x05,0x40,0x07,}; 
    char SevenA[6]  = {0x40,0x04,0x40,0x03,0xC0,0x00,};
    char EightA[6]  = {0xC0,0x07,0x40,0x05,0xC0,0x07,};
    char NineA[6]   = {0xC0,0x05,0x40,0x05,0xC0,0x07,};
    char TenA[6]    = {0x00,0x01,0x80,0x03,0x00,0x01,};

int *mCount;     //address holder
char var = 4;    //Just random number for illustration

int *XYZ[11]={&ZeroA,&OneA,&TwoA,&ThreeA,&FourA,&FiveA,&SixA,&SevenA,&EightA,&NineA,&TenA};

mCount = XYZ[Var];   

Solution

  • ZeroA and so one are pointers to an array of char elements. &ZeroA holds the address of the pointer to the array ZeroA and so to hold it you need char **

    The correct way to do it in your example is like this: char *XYZ[11]={ZeroA,OneA,TwoA,ThreeA,FourA,FiveA,SixA,SevenA,EightA,NineA,TenA};