views:

2056

answers:

4

I have a C program called opencv2.0 function :

cvSaveImage( out_img_name, img);

Compiler gcc reports that

too few arguments to function cvSaveImage

The prototype of cvSaveImage in highgui.h is

CVAPI(int) cvSaveImage( const char* filename, const CvArr* image, const int* params CV_DEFAULT(0) )

After I change my call to be

cvSaveImage( out_img_name, img, 0);

The compilation is finally successful. Does it mean default values of arguments for function are only supported in C++ but not C?

Thanks and regards!

+7  A: 

Correct - Standard C does not support default arguments, neither in the C89 standard nor in the C99 standard. There may be compiler-specific extensions to support it in some compilers, but it is not standard.

Jonathan Leffler
+2  A: 

C requires a special notation if you want to use a variable number of arguments.

http://www.swig.org/Doc1.3/Varargs.html

You can't define a default variable to be passed in to a plain function. You could set-up a macro that auto-magically passes in a default value and use that as your function entry if you want to.

jeremyosborne
A: 

stay with ANSI C

Arabcoder
A: 

I guess that just happens in new versions of opencv, I didn't get this error with the old version available on ubuntu repositories, but when I compiled the new version, the code that used to run gave me the error you are talking about

jaime