为什么不与QUOT; GCC-STD = C99 ...."允许我用沃拉斯? [英] Why won't "gcc-std=c99 ...." allow me to use VLAs?
问题描述
我试图编译下面使用code
GCC -c -g -std = C99 -MMD -MP -MF构建/调试/ Cygwin_4.x-的Windows / main.od-o建设/调试/ Cygwin_4.x-的Windows / main.o中主力。 CPP
块引用>下code使用VLA的函数func,我相信应该由C99,我相信我是用通过标志-std = C99的支持。
问题是,当我运行此我得到以下警告和错误:
cc1plus:警告:命令行选项'-std = C99'是有效的C / ObjC但不能用于C ++
的main.cpp:11:35:错误:使用参数之外的函数体之前']'令牌
无效FUNC(INT A,INT B,INT ARRY [A] [B]){
^
的main.cpp:11:38:错误:使用参数之外的函数体之前']'令牌
无效FUNC(INT A,INT B,INT ARRY [A] [B]){
块引用>第一个警告使我的问题,如果GCC试图编译code作为C或C ++。第二个让我觉得有使用VLA功能的问题,虽然我的理解是,C99应该支持。
在code是:
无效FUNC(INT A,INT B,INT ARRY [A] [B]){
//做东西
}
INT主(INT ARGC,字符** argv的){ INT的setSize = 6;
int用于设置[的setSize] [的setSize] = {0}; FUNC(的setSize,的setSize,套); 返回0;
}
解决方案
GCC
是GNU编译器的收藏的,可以作为前端作用更多只是C(虽然不使用特定语言的垫片可能会失败,没有通过额外的选项,如果它工作在所有)。如果您的文件不具有正确的扩展,你可以明确地通过
-x
,例如-xc $ C设置语言$ C>你的情况。
然而,preferable选择是将固定文件名
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; }
解决方案
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.
这篇关于为什么不与QUOT; GCC-STD = C99 ...."允许我用沃拉斯?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!