我认为下面的代码应该用 VS'2013 C 编译器编译,但它看起来像一个标识符定义在 if
之后没有括号(1 行 if
... ) 不工作
不起作用,我收到以下错误:
1>..\..\common\threadpool.c(82): error C2275: 'test_t' : illegal use of this type as an expression
1> ..\..\common\threadpool.c(75) : see declaration of 'test_t'
1>..\..\common\threadpool.c(82): error C2065: 'pool' : undeclared identifier
typedef struct { int j; } test_t;
int f(test_t **p_pool, int i)
{
if (i <= 0)
return -1;
test_t *pool;
*p_pool = pool;
return i;
}
作品
typedef struct { int j; } test_t;
int f(test_t **p_pool, int i)
{
if (i <= 0) {
return -1;
}
test_t *pool;
*p_pool = pool;
return i;
}
您是否有变通办法来构建一个巨大的遗留代码库,在这种代码库中,这种代码可能会出现很多时间?
最佳答案
代码有效,应该可以编译。它并不表示这是一个编译器错误。您应该向 Microsoft 提交错误报告。
要解决此问题,您需要执行以下操作之一:
- 从 Microsoft 获取编译器的更正版本。
- 使用不同的编译器,例如真正的 C99 编译器。
- 修改代码以避开错误的编译错误。
关于使用 C99 编译问题是否在每个 if 周围都有一个范围?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23106389/