Define Array in C

前端 未结 3 1969
盖世英雄少女心
盖世英雄少女心 2021-01-02 03:53

I have several 450 element character arrays (storing bitmap data to display on lcd screens.) I would like to put them under a header file and #define them, but

3条回答
  •  一整个雨季
    2021-01-02 04:27

    I have had a similar problem. In my case, I needed an array of constants in order to use as size of other static arrays. When I tried to use the

    const int my_const_array[size] = {1, 2, 3, ... };
    

    and then declare:

    int my_static_array[my_const_array[0]];
    

    I get an error from my compiler:

    array bound is not an integer constant
    

    So, finally I did the following (Maybe there are more elegant ways to do that):

    #define element(n,d) ==(n) ? d :
    #define my_const_array(i) (i) element(0,1) (i) element(1,2) (i) element(2,5) 0
    

提交回复
热议问题