OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-old/] [gcc-4.2.2/] [gcc/] [testsuite/] [objc.dg/] [va-meth-1.m] - Blame information for rev 816

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 149 jeremybenn
/* Based on objc/execute/va_method.m, by Nicola Pero */
2
/* { dg-do run } */
3
 
4
#include <objc/Object.h>
5
#include <stdarg.h>
6
#include <stdlib.h>
7
 
8
/* Test methods with "C-style" trailing arguments, with or without ellipsis. */
9
 
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, ...;
15
@end
16
 
17
@implementation MathClass
18
+ (int) sum: (int)firstNumber, int secondNumber, ...
19
{
20
  va_list ap;
21
  int sum = 0, number = 0;
22
 
23
  va_start (ap, secondNumber);
24
  number = firstNumber + secondNumber;
25
 
26
  while (number >= 0)
27
    {
28
      sum += number;
29
      number = va_arg (ap, int);
30
    }
31
 
32
  va_end (ap);
33
 
34
  return sum;
35
}
36
+ (int) prod: (int) firstNumber, int secondNumber, int thirdNumber {
37
  return firstNumber * secondNumber * thirdNumber;
38
}
39
+ (int) minimum: (int)firstNumber, ...
40
{
41
  va_list ap;
42
  int minimum = 999, number = 0;
43
 
44
  va_start (ap, firstNumber);
45
  number = firstNumber;
46
 
47
  while (number >= 0)
48
    {
49
      minimum = (minimum < number ? minimum: number);
50
      number = va_arg (ap, int);
51
    }
52
 
53
  va_end (ap);
54
 
55
  return minimum;
56
}
57
@end
58
 
59
int main (void)
60
{
61
  if ([MathClass sum: 1, 2, 3, 4, 5, -1] != 15)
62
      abort ();
63
  if ([MathClass prod: 4, 5, 6] != 120)
64
      abort ();
65
  if ([MathClass minimum: 17, 9, 133, 84, 35, -1] != 9)
66
      abort ();
67
 
68
  return 0;
69
}

powered by: WebSVN 2.1.0

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