C 中定义枚举和长度数组时出现冲突类型错误

问题描述 投票:0回答:1

我正在制作一个包含枚举的二维数组来描述参数的长度以及关联的其他参数的长度(0或1)

** rief 这是一个保存成像参数长度的数组

  • 注意长度值以字节为单位*/
const uint8_t xScape_ImgParamsLength[][2]={
    [IMGPARAM_THUMBNAILFACTOR]=1,0,
    [IMGPARAM_PLATFORMID]=2,0,
    [IMGPARAM_INSTRUMENTID]=2,0,
    [IMGPARAM_BINNINGFACTOR]=1,0,
    [IMGPARAM_PGAGAIN]=1,0,
    [IMGPARAM_ADCGAIN]=1,0,
    [IMGPARAM_DARKOFFSET]=2,0,
    [IMGPARAM_NUMBEROFFRAMES]=1,0,
    [IMGPARAM_FRAMEINTERVAL]=4,0,
    [IMGPARAM_ENCODING]=1,0,
    [IMGPARAM_EXPOSURETIME]=4,0,
    [IMGPARAM_ENCODINGBITOFFSET]=1,0,
    [IMGPARAM_LINES]=4,0,
    [IMGPARAM_LINEPERIOD]=4,0,
    [IMGPARAM_BANDSETUP]=1,1,
    [IMGPARAM_BANDSTARTROW]=2,1,
    [IMGPARAM_SCANDIRECTION]=1,0,
    [IMGPARAM_BLACKLEVEL]=2,0,
    [IMGPARAM_ENCODINGLINESCAN]=1,0,
    [IMGPARAM_ENCODINGBITOFFSETLINESCAN]=1,0
    };

但它不断给我同样的错误“'xScape_ImgParamsLength'的类型冲突;有'const uint8_t[][2]'{aka'const unsigned char[][2]'}”......我认为定义的枚举自动是 int ..但是在这个数组中它是 uint ,所以这就是为什么它给出错误..但我不知道如何解决它

我找不到解决方案

c eclipse multidimensional-array typecasting-operator
1个回答
0
投票

我没有时间填写所有枚举,但它可以编译并运行

#include <stdio.h>
#include <stdint.h>

enum bla {
    IMGPARAM_THUMBNAILFACTOR,
    IMGPARAM_PLATFORMID,
    IMGPARAM_INSTRUMENTID,
    IMGPARAM_BINNINGFACTOR,
    IMGPARAM_PGAGAIN,
    IMGPARAM_ADCGAIN,
    IMGPARAM_DARKOFFSET,
    IMGPARAM_NUMBEROFFRAMES,
    IMGPARAM_FRAMEINTERVAL,
    IMGPARAM_ENCODING,
    IMGPARAM_EXPOSURETIME,
    IMGPARAM_ENCODINGBITOFFSET,
    IMGPARAM_LINES,
    IMGPARAM_LINEPERIOD,
    IMGPARAM_BANDSETUP,
    IMGPARAM_BANDSTARTROW,
    IMGPARAM_SCANDIRECTION,
    IMGPARAM_BLACKLEVEL,
    IMGPARAM_ENCODINGLINESCAN,
    IMGPARAM_ENCODINGBITOFFSETLINESCAN
    }; 

const uint8_t xScape_ImgParamsLength[][2]={
    [IMGPARAM_THUMBNAILFACTOR]={1,0},
    [IMGPARAM_PLATFORMID]={2,0},
    [IMGPARAM_INSTRUMENTID]={2,0},
    [IMGPARAM_BINNINGFACTOR]={1,0},
    [IMGPARAM_PGAGAIN]={1,0},
    [IMGPARAM_ADCGAIN]={1,0},
    [IMGPARAM_DARKOFFSET]={2,0},
    [7]={1,0},
    [8]={4,0},
    [9]={1,0},
    [10]={4,0},
    [11]={1,0},
    [12]={4,0},
    [13]={4,0},
    [14]={1,1},
    [15]={2,1},
    [16]={1,0},
    [17]={2,0},
    [18]={1,0},
    [19]={1,0}
    };

    
int main() {

   printf("value: %d, %d\n", xScape_ImgParamsLength[IMGPARAM_DARKOFFSET][0],
                             xScape_ImgParamsLength[IMGPARAM_DARKOFFSET][1]);
   return 0;
}
© www.soinside.com 2019 - 2024. All rights reserved.