mardi 28 juin 2016

Using VLAs in a C++11 environment

I got C-Code that already exists and that makes use of C99-style VLAs. Like this one:

 int foo(int n, double l[n][n], double a[n][n]);

I'd like to include the headers in my C++11 project. As C++ doesn't allow these kind of constructs I'm using extern "C" to include these header files. However the compiler doesn't like this at all.

./header.h:23:42: error: use of parameter outside function body before ‘]’ token
 void foo(int n, double l[n][n], double x[n], double b[n]);
                           ^
./header.h:23:45: error: use of parameter outside function body before ‘]’ token
 void foo(int n, double l[n][n], double x[n], double b[n]);
                              ^
./header.h:23:46: error: expected ‘)’ before ‘,’ token
 void foo(int n, double l[n][n], double x[n], double b[n]);
                               ^
./header.h:23:48: error: expected unqualified-id before ‘double’
 void foo(int n, double l[n][n], double x[n], double b[n]);
                                 ^~~~~~

I think I read somewhere that VLAs became optional in C11. Does this mean that gcc got rid of it completely? If so what can I do other than extern "C"? Of course I can compile the source with an older C-standard. But I have to include the headers somehow. Any idea?

Rewriting the whole thing would only be a method of last resort.

Aucun commentaire:

Enregistrer un commentaire