gpt4 book ai didi

c - 为什么 "gcc-std=c99 ...."不允许我使用 VLA?

转载 作者:太空宇宙 更新时间:2023-11-04 08:18:15 25 4
gpt4 key购买 nike

<分区>

我正在尝试使用

编译下面的代码

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

下面的代码在函数 func 中使用了 VLA,我相信它应该得到 c99 的支持,我相信我正在通过标志 -std=c99 使用它。

问题是当我运行它时,我收到以下警告和错误:

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]){

第一个警告让我怀疑 gcc 是否试图将代码编译为 c 或 c++。第二个让我觉得使用 VLA 功能有问题,尽管我的理解是 c99 应该支持它。

代码是:

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;
}

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com