why does this compile? cygwin GCC 3.4.4

E

eduzea

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
 
V

Victor Bazarov

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
 
D

Default User

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
 
J

James Kanze

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.)
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top