I'm writing some code in C++ that needs to call a library written in C99. This library uses C99-style array declarations with the static
keyword in its function parameters. I.e., as such:
void my_func(int n, int my_ints[static n]);
However, when including the headers of this library in my C++ project, the compiler (clang) throws an warning when using the -pedantic
flag:
> g++ -pedantic -c my_code.cpp
In file included from my_code.cpp:
./my_c_lib.h: warning: variable length arrays are a C99 feature [-Wvla-extension]
void my_func(int n, int my_ints[static n]);
What is the correct/best way to call the C library in this case? Besides turning off the vla-extension
warning, is there some way around it that does not involve rewriting the library's headers or writing an intermediate C wrapper?
Minimal working example:
extern "C" {
void my_func(int n, int my_ints[static n]);
}
int main()
{
int* some_ints = new int[10];
my_func(10, some_ints);
delete[] some_ints;
return 0;
}
-pedantic
flag? It is like it flag states it is designed to force you to adhere to pedantic ANSI standards, which is more strict then just the-ANSI
flag, which is already fairly strict. By using a C99 feature you aren't coding to pedantic standards.g++
correctly warns for it -- hence my question. The library itself is compiled usinggcc -c -std=c99 -pedantic
in which case VLAs should be fine, right?