1 /* Based on objc/execute/va_method.m, by Nicola Pero */
4 #include <objc/Object.h>
8 /* Test methods with "C-style" trailing arguments, with or without ellipsis. */
10 @interface MathClass: Object
11 /* sum positive numbers; -1 ends the list */
12 + (int) sum: (int)firstNumber, int secondNumber, ...;
13 + (int) prod: (int) firstNumber, int secondNumber, int thirdNumber;
14 + (int) minimum: (int) firstNumber, ...;
17 @implementation MathClass
18 + (int) sum: (int)firstNumber, int secondNumber, ...
21 int sum = 0, number = 0;
23 va_start (ap, secondNumber);
24 number = firstNumber + secondNumber;
29 number = va_arg (ap, int);
36 + (int) prod: (int) firstNumber, int secondNumber, int thirdNumber {
37 return firstNumber * secondNumber * thirdNumber;
39 + (int) minimum: (int)firstNumber, ...
42 int minimum = 999, number = 0;
44 va_start (ap, firstNumber);
49 minimum = (minimum < number ? minimum: number);
50 number = va_arg (ap, int);
61 if ([MathClass sum: 1, 2, 3, 4, 5, -1] != 15)
63 if ([MathClass prod: 4, 5, 6] != 120)
65 if ([MathClass minimum: 17, 9, 133, 84, 35, -1] != 9)