This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

C163 - unknown array size

Hi,
why do I get this c163, if I try to compile following sequence? Shouldn't be a problem for a c-compiler to determine the array-size.

code const char code *EinstellMenue[][] = {{
" Einstellungen ",
" (up/dn/esc) ",
" F1 Messstellen ",
" F2 Kalibrierung ",
" F3 Verschiedenes ",
" F4 Statistik "
},{
" Settings ",
" (up/dn/esc) ",
"F1 Measuring points ",
"F2 Calibration ",
"F3 Miscellaneous ",
"F4 Statistic "
}};

Regards
Eckhard

Parents
  • In your array declaration:

    code const char code *EinstellMenue[][]
    

    You have 2 unspecified array indices. When the compiler generates code that accesses an element in the array it must use mathematical calculations to determine the address of the element. When you do not specify the array size, the compiler cannot do that and you receive the Unknown Array Size error.

    In C, you may exclude one array size specification but ONLY if the compiler can determine the size of the object in the array.

    For example,

    char array [] =  { 1,2,3,4 };
    

    is OK because array is an array of chars (which are 1 byte).

    char array [][4] = { 1,2,3,4,5,6,7,8 };
    

    is OK because array is an array of an array of 4 chars (which is 4 bytes).

    char array [][] = { 1,2,3,4,5,6 };
    

    is NOT OK because the array is an array of some chars. How many? 2, 3, 6, 1. It is not the compiler's job to guess.

    Also, the compiler will not guess by any clever grouping that your code implies. For example:

    char array [][] = {{1,2},{3,4},{5,6}};
    

    is also NOT OK.

    Hope this helps.

    Jon

Reply
  • In your array declaration:

    code const char code *EinstellMenue[][]
    

    You have 2 unspecified array indices. When the compiler generates code that accesses an element in the array it must use mathematical calculations to determine the address of the element. When you do not specify the array size, the compiler cannot do that and you receive the Unknown Array Size error.

    In C, you may exclude one array size specification but ONLY if the compiler can determine the size of the object in the array.

    For example,

    char array [] =  { 1,2,3,4 };
    

    is OK because array is an array of chars (which are 1 byte).

    char array [][4] = { 1,2,3,4,5,6,7,8 };
    

    is OK because array is an array of an array of 4 chars (which is 4 bytes).

    char array [][] = { 1,2,3,4,5,6 };
    

    is NOT OK because the array is an array of some chars. How many? 2, 3, 6, 1. It is not the compiler's job to guess.

    Also, the compiler will not guess by any clever grouping that your code implies. For example:

    char array [][] = {{1,2},{3,4},{5,6}};
    

    is also NOT OK.

    Hope this helps.

    Jon

Children
  • Since C166 is supposed to be an ANSI C compiler, I tried to verify that the 'common sense' approach does not deviate from the standard. I have the ISO C 1999 standard, but I don't think it differs from ANSI C in this matter.
    It says:
    The element type shall not be an incomplete or function type.
    An array with unspecified size is an incomplete type. Since a two-dimensional array is an array of arrays, it should mean that one of the two indices in a two-dimensional array declarator must be specified.
    Now which one can be omitted: the one on the left or the one on the right? According to common sense, the one on the left. Funny, I could not derive that from the text of the standard.
    Regards,
    - Mike