"error: too few arguments to function"

27,820

Solution 1

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.

Solution 2

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.

Share:
27,820
Tim
Author by

Tim

Elitists are oppressive, anti-intellectual, ultra-conservative, and cancerous to the society, environment, and humanity. Please help make Stack Exchange a better place. Expose elite supremacy, elitist brutality, and moderation injustice to https://stackoverflow.com/contact (complicit community managers), in comments, to meta, outside Stack Exchange, and by legal actions. Push back and don't let them normalize their behaviors. Changes always happen from the bottom up. Thank you very much! Just a curious self learner. Almost always upvote replies. Thanks for enlightenment! Meanwhile, Corruption and abuses have been rampantly coming from elitists. Supportive comments have been removed and attacks are kept to control the direction of discourse. Outright vicious comments have been removed only to conceal atrocities. Systematic discrimination has been made into policies. Countless users have been harassed, persecuted, and suffocated. Q&A sites are for everyone to learn and grow, not for elitists to indulge abusive oppression, and cover up for each other. https://softwareengineering.stackexchange.com/posts/419086/revisions https://math.meta.stackexchange.com/q/32539/ (https://i.stack.imgur.com/4knYh.png) and https://math.meta.stackexchange.com/q/32548/ (https://i.stack.imgur.com/9gaZ2.png) https://meta.stackexchange.com/posts/353417/timeline (The moderators defended continuous harassment comments showing no reading and understanding of my post) https://cs.stackexchange.com/posts/125651/timeline (a PLT academic had trouble with the books I am reading and disparaged my self learning posts, and a moderator with long abusive history added more insults.) https://stackoverflow.com/posts/61679659/revisions (homework libels) Much more that have happened.

Updated on May 26, 2020

Comments

  • Tim
    Tim almost 4 years

    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!