Debian Codegraph @

gcc/testsuite/objc/execute/va_method.m

raw
1 /* Contributed by Nicola Pero - Thu Mar 8 16:27:46 CET 2001 */
2 #include <objc/objc.h>
3 #include <stdarg.h>
4
5 /* Test method with variable number of arguments */
6
7 @interface MathClass
8 {
9 Class isa;
10 }
11 /* sum positive numbers; -1 ends the list */
12 + (int) sum: (int)firstNumber, ...;
13 @end
14
15 @implementation MathClass
16 + (int) sum: (int)firstNumber, ...
17 {
18 va_list ap;
19 int sum = 0, number = 0;
20
21 va_start (ap, firstNumber);
22 number = firstNumber;
23
24 while (number >= 0)
25 {
26 sum += number;
27 number = va_arg (ap, int);
28 }
29
30 va_end (ap);
31
32 return sum;
33 }
34 + initialize { return self; }
35 @end
36
37 int main (void)
38 {
39 if ([MathClass sum: 1, 2, 3, 4, 5, -1] != 15)
40 {
41 abort ();
42 }
43
44 return 0;
45 }