Why won't “gcc-std=c99 …” allow me to use VLAs? [closed]

和自甴很熟 提交于 2019-12-13 06:45:22

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!