Variable number of arguments to a function

vijay hemraj jadhwani thssvhj at iitmax.IIT.EDU
Sun May 6 08:28:28 AEST 1990


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.



More information about the Comp.lang.c mailing list