5

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

2 Answers 2

3

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};
Sign up to request clarification or add additional context in comments.

2 Comments

It wasn't my downvote, but I don't see where his code uses a pointer from tmp uninitialized. He's assigning to the ith item of tmp, not dereferencing it. It's hardly undefined behavior to assign to an uninitialized pointer.
@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, .... :(
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. */

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.