Path: utzoo!utgpu!news-server.csri.toronto.edu!rutgers!usc!zaphod.mps.ohio-state.edu!ncar!tank!iitmax!thssvhj From: thssvhj@iitmax.IIT.EDU (vijay hemraj jadhwani) Newsgroups: comp.lang.c Subject: Variable number of arguments to a function Keywords: c, variable number of arguments, sprintf Message-ID: <3697@iitmax.IIT.EDU> Date: 5 May 90 22:28:28 GMT Distribution: na Organization: Illinois Institute of Technology, Chicago Lines: 49 Here is a question for c folks. I have a function myprint() as follows - myprint(stream, fmt, a1, a2, a3, a4, a5) /* Function definition */ FILE *stream; char *fmt; { ... some initialization and assignment ... sprintf(stream, fmt, a1, a2, a3, a4, a5); . . . } Below are the three different cases of function references (or usage). Case 1. ACTUAL NO. OF ARGUMENTS < NO. OF ARGUMENTS IN THE FUNC. DEFINITION int test_no = 1; myprint(stderr, "This is just test number %d", test_no); Case 2. ACTUAL NO. OF ARGUMENTS > NO. OF ARGUMENTS IN THE FUNC. DEFINITION int a, b, c, d, e, f; myprint(stderr, "The values are %d %d %d %d %d %d", a, b, c, d, e, f); Case 3: ARGUMENT TYPE IS DIFFERENT THAN THE EXPECTED ARGUMENT TYPE int a; float b; /* This argument type is different; default type is int */ int c, d, e; myprint(stderr, "The values are %d %f %d %d %d", a, b, c, d, e); Questions - 1. Which of the above 3 cases are correct and which are not? Why ? 2. If I want to remove any "lint" warnings, for argument number mismatch, what should I do ? i.e. I need a scheme to be able to pass variable number of arguments to myprint(). Also it would be nice , if I could also have an ability to pass any "type" of arguments to myprint(). Thanks in advance for any help. Vijay.