问题
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;
}
回答1:
gcc
is the Gnu Compiler Collection and can act as frontend for more that just C (though not using the language-specific shim might fail without passing additional options, if it works at all).
If your file doesn't have the correct extension, you may set the language explicitly via -x
, eg -xc
in your case.
However, the preferable option would be to fix the filename.
来源:https://stackoverflow.com/questions/34561723/why-wont-gcc-std-c99-allow-me-to-use-vlas