I have a C program called opencv2.0 function :
我有一个C程序,叫做opencv2.0功能:
cvSaveImage( out_img_name, img);
Compiler gcc reports that
编译器gcc报道,
too few arguments to function cvSaveImage
函数cvSaveImage的参数太少
The prototype of cvSaveImage in highgui.h is
在highgui中cvSaveImage的原型。h是
CVAPI(int) cvSaveImage( const char* filename, const CvArr* image, const int* params CV_DEFAULT(0) )
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?
编译终于成功了。它是否意味着函数参数的默认值仅在c++中支持,而在C中不支持?
Thanks and regards!
感谢和问候!
2 个解决方案
#1
15
Correct - Standard C does not support default arguments, neither in the C89 standard nor in the C99 standard (nor in the C2011 standard). There may be compiler-specific extensions to support it in some compilers, but it is not standard.
正确-标准C不支持默认参数,无论是C89标准还是C99标准(也不是C2011标准)。在某些编译器中可能有特定于编译器的扩展来支持它,但它不是标准的。
#2
2
C requires a special notation if you want to use a variable number of arguments.
如果要使用可变数量的参数,C需要一个特殊的符号。
http://www.swig.org/Doc1.3/Varargs.html
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.
不能定义要传递给普通函数的默认变量。您可以设置一个宏,该宏自动地传入一个默认值,如果您愿意,可以将其用作函数条目。
#1
15
Correct - Standard C does not support default arguments, neither in the C89 standard nor in the C99 standard (nor in the C2011 standard). There may be compiler-specific extensions to support it in some compilers, but it is not standard.
正确-标准C不支持默认参数,无论是C89标准还是C99标准(也不是C2011标准)。在某些编译器中可能有特定于编译器的扩展来支持它,但它不是标准的。
#2
2
C requires a special notation if you want to use a variable number of arguments.
如果要使用可变数量的参数,C需要一个特殊的符号。
http://www.swig.org/Doc1.3/Varargs.html
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.
不能定义要传递给普通函数的默认变量。您可以设置一个宏,该宏自动地传入一个默认值,如果您愿意,可以将其用作函数条目。