gpt4 book ai didi

c - 具有 typedef 和数组时 c 中 const 的问题

转载 作者:太空狗 更新时间:2023-10-29 15:08:48 25 4
gpt4 key购买 nike

<分区>

我有以下代码:

typedef float vec3_t[3];

void f(const vec3_t v[2]){
// do stuff
}

int main(int argc, char * argv[]){
vec3_t v[2];
v[2][1] = 1;
f(v);
return 0;
}

不会编译使用

gcc main.c -std=gnu99 -O0 -o main

但报错

main.c: In function ‘main’:'
main.c:293:5: warning: passing argument 1 of ‘f’ from incompatible pointer type [enabled by default]
f(v);
^
main.c:286:6: note: expected ‘const float (*)[3]’ but argument is of type ‘float (*)[3]’
void f(const vec3_t v[2]){
^

另一方面,如果我删除函数 f 中的 const 要求。一切正常。我不知道哪里出了问题??

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