#1
  1. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2002
    Posts
    421
    Rep Power
    12

    Borland doesn't like an empty array matrix?


    Borland C++ doesn't like when I define an array like this:

    char test[];

    For some reason a number always needs to be in the []..why is that?

    -andy
    hmmm...
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2002
    Posts
    272
    Rep Power
    19
    You are defining an array for which space will be allocated. The compiler needs to know how much space to allocate. You can use the [] in a declaration, but not in a definition.
  4. #3
  5. Contributing User
    Devshed Supreme Being (6500+ posts)

    Join Date
    Jan 2003
    Location
    USA
    Posts
    7,172
    Rep Power
    2222
    As 3dfxMM points out, you need to tell the compiler how big the array will be so that it can allocate enough memory to it. There are a couple ways to do that:

    1. Do it explicitly; e.g.:
    char test[10];

    2. Do it implicitly with an initialization string or array; e.g.:
    char test[] = "Just do it like this";
    int itest[] = {0,1,2,3,4,5,6,7,8,9}

    If you really and honestly and truly don't want to or cannot specify its size at compile time, then use the alternative syntax and declare it as a pointer and allocate it dynamically at runtime; e.g.:
    char *test;

IMN logo majestic logo threadwatch logo seochat tools logo