C语言 赋值从指针生成整数而无需强制转换 [-Wint-conversion

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/34840080/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-02 12:18:10  来源:igfitidea点击:

Assignment makes integer from pointer without a cast [-Wint-conversion

carrayspointersvariable-assignmentuint8t

提问by Addon

I really don't understand why I have such error knowing that tmpand keyare the same type and size.

我真的不明白为什么我知道会出现这样的错误tmp并且key是相同的类型和大小。

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

警告:赋值从指针生成整数而无需强制转换 [-Wint-conversion

回答by Sourav Ghosh

tmpand keyare the same type

tmp并且key是相同的类型

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

。他们不是。它们都是数组,但数据类型不同。一个是uint8_t *数组,另一个是uint8_t数组。

Change

改变

 uint8_t *tmp[8];

to

uint8_t tmp[8] = {0};

回答by mksteve

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

尚不清楚你想要的这里,但如果你想tmp[x]以反映价值key[y],然后

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 ...

否则,如果您希望 tmp 分开,那么...

 uint8_t tmp[8];  /* change type to be non-pointer. */