C++未声明的变量

C++ undeclared variables

本文关键字:变量 未声明 C++      更新时间:2023-10-16

我在项目中使用的一个文件有很多这样的声明:

static VALUE do_checksum(int, VALUE*, uLong (*)(uLong, const Bytef*, uInt));
...
static VALUE
 do_checksum(argc, argv, func)
     int argc;
     VALUE *argv;
     uLong (*func)(uLong, const Bytef*, uInt);
 {
    ...
 }

虽然我自己从来没有用这种方式编写过代码,但我确信它是正确的。然而,我的编译器返回

error: 'VALUE do_checksum' redeclared as different kind of symbol
error: 'argc' was not declared in this scope

这里怎么了?

Windows 7

代码::块w/MinGW

您有一些旧式的C参数列表声明。

这里有一个修复示例:

static VALUE do_checksum(
    int argc,
    VALUE *argv,
    uLong (*func)(uLong, const Bytef*, uInt)
    )
{
    ...
}

更好的修复方法是为func创建一个类型别名,如下所示:

using func_ptr_type = uLong (*)(uLong, const Bytef*, uInt);