OpenCores
URL https://opencores.org/ocsvn/openrisc_2011-10-31/openrisc_2011-10-31/trunk

Subversion Repositories openrisc_2011-10-31

[/] [openrisc/] [trunk/] [gnu-src/] [gcc-4.5.1/] [gcc/] [testsuite/] [objc/] [execute/] [va_method.m] - Blame information for rev 307

Details | Compare with Previous | View Log

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

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.