RAD Studio |  |

E2021: Array must have at least one element (C++)

ANSI C and C++ require that an array be defined to have at least one element (objects of zero size are not allowed).

An old programming trick declares an array element of a structure to have zero size, then allocates the space actually needed with malloc.

You can still use this trick, but you must declare the array element to have (at least) one element if you are compiling in strict ANSI mode.

Declarations (as opposed to definitions) of arrays of unknown size are still allowed.

Example

Copy Code

    char ray[];         /* definition of unknown size -- ILLEGAL */
    char ray[0];        /* definition of 0 size -- ILLEGAL */
    extern char ray[];  /* declaration of unknown size -- OK */

Copyright(C) 2009 Embarcadero Technologies, Inc. All Rights Reserved.
What do you think about this topic? Send feedback!