0

A file I am using in my project has many declaration in this style:

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);
 {
    ...
 }

While I have never written code in this way myself, I am sure it is correct. However, my compiler returns

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

What is wrong here?

Windows 7

Code::Blocks w/ MinGW

chrisvj
  • 895
  • 1
  • 6
  • 9
  • 3
    C++ does not support C old-style parameter declaration. – Jonathan Potter Nov 12 '14 at 00:06
  • @JonathanPotter: Those are *old-style* C parameter declarations. Modern C still permits them, but they've been officially obsolescent since 1989. – Keith Thompson Nov 12 '14 at 00:08
  • See http://stackoverflow.com/questions/1585390/c-function-syntax-parameter-types-declared-after-parameter-list for a discussion. – Jonathan Potter Nov 12 '14 at 00:09
  • So I should go through and rewrite all the declarations? – chrisvj Nov 12 '14 at 00:09
  • If you intend to use this with a C++ compiler, and you have no choice, then yes. Leave forward declarations in place, just change the parameter lists. – defube Nov 12 '14 at 00:15
  • OK, hopefully last thing. "static const struct zstream_funcs inflate_funcs = { inflateReset, inflateEnd, inflate, };" says that it "has initializer but incomplete type" – chrisvj Nov 12 '14 at 00:43

1 Answers1

0

You have yourself some old-style C parameter list declarations.

Here's a sample fix:

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

An even better fix would be to make a type alias for func like so:

using func_ptr_type = uLong (*)(uLong, const Bytef*, uInt);
defube
  • 2,395
  • 1
  • 22
  • 34
  • So following your sample, I would just do away with "static VALUE do_checksum(int, VALUE*, uLong (*)(uLong, const Bytef*, uInt));" completely? – chrisvj Nov 12 '14 at 00:13
  • @chrisvj, no, looks more closely. You need to move the parameter declarations inside the () and replace commas with semi-colons – Jonathan Wakely Nov 12 '14 at 00:14
  • As far as I know, the code you're using needs it (its a forward declaration, and the ellipses implies stuff after it). – defube Nov 12 '14 at 00:14