Home | History | Annotate | Download | only in tests
      1 //
      2 //                     The LLVM Compiler Infrastructure
      3 //
      4 // This file is distributed under the University of Illinois Open Source
      5 // License. See LICENSE.TXT for details.
      6 
      7 //  -*- mode:C; c-basic-offset:4; tab-width:4; intent-tabs-mode:nil;  -*-
      8 // CONFIG
      9 
     10 #import <stdio.h>
     11 #import <stdlib.h>
     12 #import <string.h>
     13 
     14 typedef struct {
     15     unsigned long ps[30];
     16     int qs[30];
     17 } BobTheStruct;
     18 
     19 int main (int argc, const char * argv[]) {
     20     BobTheStruct inny;
     21     BobTheStruct outty;
     22     BobTheStruct (^copyStruct)(BobTheStruct);
     23     int i;
     24 
     25     memset(&inny, 0xA5, sizeof(inny));
     26     memset(&outty, 0x2A, sizeof(outty));
     27 
     28     for(i=0; i<30; i++) {
     29         inny.ps[i] = i * i * i;
     30         inny.qs[i] = -i * i * i;
     31     }
     32 
     33     copyStruct = ^(BobTheStruct aBigStruct){ return aBigStruct; };  // pass-by-value intrinsically copies the argument
     34 
     35     outty = copyStruct(inny);
     36 
     37     if ( &inny == &outty ) {
     38         printf("%s: struct wasn't copied.", argv[0]);
     39         exit(1);
     40     }
     41     for(i=0; i<30; i++) {
     42         if ( (inny.ps[i] != outty.ps[i]) || (inny.qs[i] != outty.qs[i]) ) {
     43             printf("%s: struct contents did not match.", argv[0]);
     44             exit(1);
     45         }
     46     }
     47 
     48     printf("%s: success\n", argv[0]);
     49 
     50     return 0;
     51 }
     52