g++ with VLA

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



https://gcc.gnu.org/onlinedocs/gcc/Variable-Length.html

That doc states that VLAs are supported in C++ as an extension.
Compiling the following:

void f(int a, int b[a]);
void f() {
  int c[2];
  f(2, c);
}

with g++ -std=gnu++20 results in the error: "use of parameter outside
function body before ']' token".  The docs say nothing about partial
support of VLA, just that they can be used.

Where this is useful as an extension is in the somewhat reasonable
case of including a C header in a C++ program.  If that C header
declares a function using a C99 VLA, it would be awesome if g++ were
to accept it in -std=gnu++ mode (and it would be fine if it were
rejected in -std=c++ mode).  Consider a situation where you cannot
modify the header, and so have to use it as-is.

Is there perhaps another option to achieve the intended behavior?

If it's not possible, can this be added?

If the consensus is that it shouldn't be added, could the docs at
least clarify what is supported and what is not in C++?



[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux