why does this compile? cygwin GCC 3.4.4

Discussion in 'C++' started by eduzea@gmail.com, Jul 19, 2007.

  1. Guest

    int main()
    {
    int variable;
    int array[variable];
    }

    As I understand it, array should be compiler allocated, so it cannot
    have a variable as size.

    Thanks,

    Eduardo
     
    , Jul 19, 2007
    #1
    1. Advertising

  2. wrote:
    > int main()
    > {
    > int variable;
    > int array[variable];
    > }
    >
    > As I understand it, array should be compiler allocated, so it cannot
    > have a variable as size.


    It's a C++ "extension" g++ provides. Learn the compiler options that
    don't allow extensions.

    V
    --
    Please remove capital 'A's when replying by e-mail
    I do not respond to top-posted replies, please don't ask
     
    Victor Bazarov, Jul 19, 2007
    #2
    1. Advertising

  3. Default User Guest

    wrote:

    >
    > int main()
    > {
    > int variable;
    > int array[variable];
    > }
    >
    > As I understand it, array should be compiler allocated, so it cannot
    > have a variable as size.


    That's a gcc extension. Use the correct compiler flags to force it to
    standard mode.




    Brian
     
    Default User, Jul 19, 2007
    #3
  4. James Kanze Guest

    On Jul 19, 10:12 pm, "" <> wrote:
    > int main()
    > {
    > int variable;
    > int array[variable];
    > }


    > As I understand it, array should be compiler allocated, so it
    > cannot have a variable as size.


    You understand correctly. For C++, anyway; in C, it's legal.
    Some compilers allow it by default in C++ as well; you should
    generally make sure you use the options necessary to turn off
    all extensions except those you explicitly want. (About the
    only extension I normally use is Posix support.)

    --
    James Kanze (GABI Software) email:
    Conseils en informatique orientée objet/
    Beratung in objektorientierter Datenverarbeitung
    9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34
     
    James Kanze, Jul 20, 2007
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    0
    Views:
    459
  2. Replies:
    0
    Views:
    434
  3. Mr. SweatyFinger
    Replies:
    2
    Views:
    1,993
    Smokey Grindel
    Dec 2, 2006
  4. Replies:
    5
    Views:
    362
    Nathan Addy
    Sep 17, 2005
  5. fAnSKyer
    Replies:
    2
    Views:
    534
    Alf P. Steinbach
    Jun 7, 2009
Loading...

Share This Page