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