gpt4 book ai didi

c - 任何 gcc 选项可以像 "int i[]"一样对待 "int *i"吗?

转载 作者:行者123 更新时间:2023-11-30 19:57:14 25 4
gpt4 key购买 nike

较旧的 C 编译器似乎对空方括号更为宽松。 gcc 可以允许这样做吗(即使不符合标准)?我正在移植一个大型代码库。

void foo() {
extern int i[]; /* gcc -c foo.c gives "incomplete type" error */
int x;
i=&x; }

更新:我在上面的示例代码中犯了错误。 AnT 提到 i不是左值。仔细检查我的旧编译器显示此代码根本无法编译。抱歉造成困惑。

最佳答案

我不知道有什么方法可以让 gcc 接受这样的代码——我建议的下一个最佳解决方案是看看是否可以像@Barmar建议的那样使用正则表达式替换(它应该检查结果相对容易,因为它当前无法编译);或者甚至尝试 Coccinelle semantic patch更安全的方法:

Coccinelle is a program matching and transformation engine which provides the language SmPL (Semantic Patch Language) for specifying desired matches and transformations in C code.

Coccinelle was initially targeted towards performing collateral evolutions in Linux. Such evolutions comprise the changes that are needed in client code in response to evolutions in library APIs, and may include modifications such as renaming a function, adding a function argument whose value is somehow context-dependent, and reorganizing a data structure.

Beyond collateral evolutions, Coccinelle is successfully used (by us and others) for finding and fixing bugs in systems code.

关于c - 任何 gcc 选项可以像 "int i[]"一样对待 "int *i"吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50420820/

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