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

Subversion Repositories openrisc_me

[/] [openrisc/] [trunk/] [gnu-src/] [gcc-4.5.1/] [gcc/] [testsuite/] [objc/] [execute/] [va_method.m] - Rev 326

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

/* 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;
}
 

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

powered by: WebSVN 2.1.0

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