使用 C99 编译问题是否在每个 if 周围都有一个范围?

标签 c visual-studio-2013

我认为下面的代码应该用 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/

相关文章:

c - 我的快速排序实现有问题

c - 质数回文逻辑效率

visual-studio-2013 - 使用最新的 Install Shield LE 定位 64 位程序文件夹

c++ - Visual Studio 2015 调试器崩溃

c# - Resharper Ultimate 安装扩展失败

c - 一个简单的for循环的输出?

c - Linux内核模块编程中_do_fork()的问题

c# - Visual Studio 在打开 Web 应用程序解决方案时创建 bin 文件夹?

c - C中这两种形式的内联汇编器有什么区别?

android - Visual Studio - 无法启动 Android SDK 管理器