1

I've been given a C/C++ code that looks like this:

extern int ZEXPORT zipOpenNewFileInZip3 (file, filename, zipfi, extrafield_local)
  zipFile file;
  const char* filename;
  const zip_fileinfo* zipfi;
  const void* extrafield_local;

{

... function body

}

Is declaring the parameters of a function like that possible? I'm getting errors from the compiler (g++).

Thanks in advance.

Dan Moulding
  • 211,373
  • 23
  • 97
  • 98
Mangel
  • 11
  • 1
  • 5
    It is possbible and known as K&R style. – Dayal rai Jul 10 '13 at 10:17
  • This isn't C/C++. That isn't a language. This is old C. – chris Jul 10 '13 at 10:17
  • 1
    This may help you : http://stackoverflow.com/questions/1630631/alternate-c-syntax-for-function-declaration-use-cases – VoidPointer Jul 10 '13 at 10:18
  • You're not the same guy as asked [this question](http://stackoverflow.com/questions/17566422/what-is-the-weird-usage-in-c-language) are you? Either way, see [these related questions](http://stackoverflow.com/questions/17566422/what-is-the-weird-usage-in-c-language#comment25556566_17566422). – Cody Gray - on strike Jul 10 '13 at 10:20
  • Old (and obsolescent) style, don't use it – David Ranieri Jul 10 '13 at 10:20
  • 1
    WOW! I don't know how many years it is, since I last have seen or used this kind of function declarations. Must be more than 20 Years or so, and now it looks so wrong. :) Those were the days... – Devolus Jul 10 '13 at 10:25
  • I've compiled using -std=C89 and it works like a charm. Thank you everyone. – Mangel Jul 10 '13 at 10:29
  • `zlib` is full of such declarations, I was also surprised by that quite recently. – riv Jul 10 '13 at 10:33
  • I borrowed an old C book some two years ago , it was probably ANSI standard . I read this kind of declaration in that book. Nostalgia :) – 0decimal0 Jul 10 '13 at 10:35

2 Answers2

2

This is a very old-school C (pre-ANSI C syntax) way for doing things. I suggest you change it, if you own the code, to

extern int ZEXPORT zipOpenNewFileInZip3 (
  zipFile file,
  const char* filename,
  const zip_fileinfo* zipfi,
  const void* extrafield_local)
...

There are some more details here and here

Community
  • 1
  • 1
doctorlove
  • 18,872
  • 2
  • 46
  • 62
0

That is ancient syntax for defining functions in C. It predates the first standardized version of the C language. More importantly, that syntax has never been valid C++. Since you are compiling this code (which is obviously C code) with a C++ compiler, it is failing.

Dan Moulding
  • 211,373
  • 23
  • 97
  • 98