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 int a; 16 int b; 17 } MiniStruct; 18 19 int main (int argc, const char * argv[]) { 20 MiniStruct inny; 21 MiniStruct outty; 22 MiniStruct (^copyStruct)(MiniStruct); 23 24 memset(&inny, 0xA5, sizeof(inny)); 25 memset(&outty, 0x2A, sizeof(outty)); 26 27 inny.a = 12; 28 inny.b = 42; 29 30 copyStruct = ^(MiniStruct aTinyStruct){ return aTinyStruct; }; // pass-by-value intrinsically copies the argument 31 32 outty = copyStruct(inny); 33 34 if ( &inny == &outty ) { 35 printf("%s: struct wasn't copied.", argv[0]); 36 exit(1); 37 } 38 if ( (inny.a != outty.a) || (inny.b != outty.b) ) { 39 printf("%s: struct contents did not match.", argv[0]); 40 exit(1); 41 } 42 43 printf("%s: success\n", argv[0]); 44 return 0; 45 } 46