conflicting types error in C when defining enum and length array

121 views Asked by At

I am making a 2D array containing enums to describe the length of the parameters and length of associated other parameter which is either 0 or 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
    };

but it's continuously giving me the same error that "conflicting types for 'xScape_ImgParamsLength'; have 'const uint8_t[][2]' {aka 'const unsigned char[][2]'}"...I think the enum defined is automatically int..but here in this array it's uint so that's why it's giving error..but I don't know how to resolve it.

i could not find the solution

1

There are 1 answers

0
Dražen Grašovec On

This subset of your code compiles and works. You just have to learn how multi-dimensional arrays are initialized in 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;
}