-2

I have a function like this

void foo( int i)
{
   ...
   uint8_t buf[ i];
   ...
}

and I don't understand why the compiler is not complaining... I'm using

g++ -c -g -Wall
to compile

Any ideas??

santi
  • 67
  • 2
  • 4

1 Answers1

1

It is a GCC compiler extension. It is allowed by the standard for a conforming implementation because it does not break any well-formed code (as long as it issues a diagnostic). It is, of course, not portable and therefore not recommended.

With the -pedantic option, you'll get the following warning:

warning: ISO C++ forbids variable length array ‘buf’ [-Wvla]
Joseph Mansfield
  • 104,685
  • 19
  • 232
  • 315