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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-stable/] [gcc-4.5.1/] [gcc/] [testsuite/] [objc.dg/] [va-meth-1.m] - Blame information for rev 309

Go to most recent revision | Details | Compare with Previous | View Log

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

powered by: WebSVN 2.1.0

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