3

I really don't understand why I have such error knowing that tmp and key are the same type and size.

uint8_t key[8] = {0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07};

void change() {

    int i;
    uint8_t *tmp[8];

    for(i=0; i<8; i++){
        tmp[i] = key[(i+3)%8];
    }
}

This produces:

warning: assignment makes integer from pointer without a cast [-Wint-conversion

Sourav Ghosh
  • 133,132
  • 16
  • 183
  • 261
Addon
  • 75
  • 1
  • 1
  • 9

2 Answers2

2

tmp and key are the same type

NO. They are not. They both are arrays, but the datatype is different. One is a uint8_t *array, another is a uint8_t array.

Change

 uint8_t *tmp[8];

to

uint8_t tmp[8] = {0};
Sourav Ghosh
  • 133,132
  • 16
  • 183
  • 261
  • 1
    It wasn't my downvote, but I don't see where his code uses a pointer from `tmp` uninitialized. He's *assigning* to the `i`th item of `tmp`, not dereferencing it. It's hardly undefined behavior to assign to an uninitialized pointer. – Cody Gray - on strike Jan 18 '16 at 05:16
  • @CodyGray You're right sir, I also got confused by the data types....Thanks for pointing that out. But then, regarding the DV, it was before I added that part, as an edit.....so, .... :( – Sourav Ghosh Jan 18 '16 at 07:51
1

Not clear what you want here but if you want tmp[x] to reflect the value in key[y] then

tmp[i] = &key[(i+3)%8]; /* tmp[i] now points at key[ (i+3)%8];
// key[3] = 5;    /* These two lines modify the same memory */
// (*tmp[0]) = 5; /*                                        */

Otherwise if you want tmp to be separate, then ...

 uint8_t tmp[8];  /* change type to be non-pointer. */
mksteve
  • 12,614
  • 3
  • 28
  • 50