-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
  • 77
  • 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
  • 108,238
  • 20
  • 242
  • 324