Variable length array

This is a discussion on Variable length array within the C Programming forums, part of the General Programming Boards category; Hey guys I tried searching for this but I can't find any info. Also, a book I'm using for reference ...

  1. #1
    671
    671 is offline
    Registered User
    Join Date
    Aug 2006
    Posts
    1

    Variable length array

    Hey guys I tried searching for this but I can't find any info. Also, a book I'm using for reference says that this is legal but I keep getting an error implying that I can't initialize my array this way. Thanks in advance.

    void main()
    {
    int blocks_to_run;

    printf("Enter the number of blocks you want to run (must be greater than 0):\n");
    scanf("%d", &blocks_to_run);

    unsigned char EncoderOut[9856*blocks_to_run];


    ..................... more code.............

  2. #2
    ... kermit's Avatar
    Join Date
    Jan 2003
    Posts
    1,528
    Variable length arrays (vlas) are an addition to the C99 standard IIRC - Even a fairly c99 compliant compiler such as gcc handle things like vlas in a not quite standard conforming fashion. Which compiler are you using, and can you show us your actual code you are trying to compile, as well as your actual warning messages.

    What might be your better bet would be to look into allocating some space with malloc and 'simulating' an array with that space.

  3. #3
    Registered User
    Join Date
    Oct 2001
    Posts
    2,934
    You may have to invoke your compiler in C99 mode. But with an array that big, malloc might be a better option.

    >void main()
    There's a FAQ entry explaining why this is wrong:
    What's the difference between... > main() / void main() / int main() / int main(void) / int main(int argc, char *argv[])

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Need some help...
    By darkconvoy in forum C Programming
    Replies: 32
    Last Post: 04-29-2008, 03:33 PM
  2. Variable length
    By 182 in forum C++ Programming
    Replies: 9
    Last Post: 02-14-2006, 07:56 PM
  3. Quick question about SIGSEGV
    By Cikotic in forum C Programming
    Replies: 30
    Last Post: 07-01-2004, 07:48 PM
  4. array length
    By Wick in forum C++ Programming
    Replies: 3
    Last Post: 08-30-2003, 04:53 PM
  5. making an array name a variable
    By Zaarin in forum C++ Programming
    Replies: 5
    Last Post: 09-02-2001, 06:17 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21