summaryrefslogtreecommitdiff
path: root/gcc/testsuite/objc/execute/va_method.m
blob: 51619b8d3130377c0010261ead08f7545b94c318 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
/* Contributed by Nicola Pero - Thu Mar  8 16:27:46 CET 2001 */
#include <objc/objc.h>
#include <objc/objc-api.h>
#include <stdarg.h>

/* Test method with variable number of arguments */

@interface MathClass
{
  Class isa;
}
/* sum positive numbers; -1 ends the list */
+ (int) sum: (int)firstNumber, ...;
@end

@implementation MathClass
+ (int) sum: (int)firstNumber, ...
{
  va_list ap;
  int sum = 0, number = 0;

  va_start (ap, firstNumber);
  number = firstNumber;

  while (number >= 0)
    {
      sum += number;
      number = va_arg (ap, int);
    }
  
  va_end (ap);

  return sum;
}
#ifdef __NEXT_RUNTIME__                                   
+ initialize { return self; }
#endif
@end

int main (void)
{
  if ([MathClass sum: 1, 2, 3, 4, 5, -1] != 15)
    {
      abort ();
    }
  
  return 0;
}