I am trying to compile the code below using
gcc -c -g -std=c99 -MMD -MP -MF "build/Debug/Cygwin_4.x-Windows/main.o.d" -o build/Debug/Cygwin_4.x-Windows/main.o main.cpp
The code below uses VLA in the function func, which I believe should be supported by c99 which I believe I am using via the flag -std=c99.
The problem is when I run this I get the following warning and errors:
cc1plus: warning: command line option '-std=c99' is valid for C/ObjC but not for C++
main.cpp:11:35: error: use of parameter outside function body before ']' token void func(int a, int b, int arry[a][b]){ ^
main.cpp:11:38: error: use of parameter outside function body before ']' token void func(int a, int b, int arry[a][b]){
The first warning makes me question if gcc is trying to compile the code as c or c++. The second makes me think that there is a problem using the VLA features, although my understanding is that c99 should support that.
The code is:
void func(int a, int b, int arry[a][b]){
//Do stuff
}
int main(int argc, char** argv) {
int setSize=6;
int sets[setSize][setSize]={0};
func(setSize,setSize,sets);
return 0;
}
main.cpp
if it's not C++? Or is it?cc1plus
, in addition to the fact that C++ doesn't allow VLAs at all..cpp
file, it'll compile it as C++, regardless of whether you invoke it asgcc
org++
.gcc
is the Gnu Compiler Collection and can act as front-end for more than just C. If your file doesn't have the proper extension, pass-xc
to force C mode