Thread: Variable length arrays

  1. #1
    Registered User
    Join Date
    Feb 2010
    Posts
    72

    Variable length arrays

    If I remember right C90 doesn't support variable length arrays, while C99 does support them(see Status of C99 features in GCC - GNU Project - Free Software Foundation (FSF))

    so, is it ok to use variable length arrays when using C99 dialect?

    my professor says that the compiler will show error if I say for example

    Code:
    int n=10;
    int x[n];
    but that's not correct, some compilers show error some don't, but this really does have to do with the dialect right?

    also he taught us about one line comments, after a little research i found that in c90 they are forbidden, while in C99 they are allowed(see again Status of C99 features in GCC - GNU Project - Free Software Foundation (FSF)). So that does mean that we're learning c99. So is he right when he tells us that a variable length array would result in an error?

  2. #2
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708
    Right, your professor is not using the current C standard. Tell him that the dark ages are over, and then do him a favor and give him a copy of the latest GCC snapshot.

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    > So that does mean that we're learning c99. So is he right when he tells us that a variable length array would result in an error?
    Seems to me like you're learning "dialect C".
    For you, this is the rag-bag of features your professor imagines to be C (which is neither C90 nor C99).

    The problem for you (and all his students past, present and future) is when they use a compiler that doesn't implement the particular flavour of C you've learnt.

    For example, the // comment thing is pretty common, but it isn't C90 and some compiler will still throw it out.

    gcc (with the various -std= flags) gives you a pretty good indication of what is really allowed at each standard.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

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. create variable size arrays
    By s-men in forum C Programming
    Replies: 6
    Last Post: 08-27-2007, 07:45 PM
  3. How to declare global arrays of unknown length?
    By ajm218 in forum C Programming
    Replies: 3
    Last Post: 08-07-2003, 09:13 AM
  4. Need help
    By awkeller in forum C Programming
    Replies: 2
    Last Post: 12-09-2001, 03:02 PM
  5. length of string etc.
    By Peachy in forum C Programming
    Replies: 5
    Last Post: 09-27-2001, 12:04 PM