C中定义枚举和长度数组时发生类型冲突错误[关闭]

wztqucjr  于 12个月前  发布在  其他
关注(0)|答案(1)|浏览(159)

**已关闭。**此问题需要debugging details。目前不接受回答。

编辑问题以包括desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem。这将帮助其他人回答问题。
22天前关闭
Improve this question
我正在创建一个包含枚举的2D数组来描述参数的长度和相关的其他参数的长度,这些参数可以是0或1。

/** \brief This is an array to hold length of the imaging parameters
 * \note Length values are in bytes*/

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,所以这就是为什么它给出错误..但我不知道如何解决它。
我找不到解决办法

ymdaylpp

ymdaylpp1#

你的代码的这个子集可以编译并工作,你只需要学习如何在C中初始化多维数组。

#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,
    /* ... */
}; 

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},
    /* ... */
};

    
int main() {

   printf("value: %d, %d\n", xScape_ImgParamsLength[IMGPARAM_FRAMEINTERVAL][0],
                             xScape_ImgParamsLength[IMGPARAM_FRAMEINTERVAL][1]);
   return 0;
}

字符串

相关问题