llvm-project
44 строки · 1.1 Кб
1//
2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
3// See https://llvm.org/LICENSE.txt for license information.
4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
5
6// -*- mode:C; c-basic-offset:4; tab-width:4; intent-tabs-mode:nil; -*-
7// CONFIG
8
9#import <stdio.h>
10#import <stdlib.h>
11#import <string.h>
12
13typedef struct {
14int a;
15int b;
16} MiniStruct;
17
18int main (int argc, const char * argv[]) {
19MiniStruct inny;
20MiniStruct outty;
21MiniStruct (^copyStruct)(MiniStruct);
22
23memset(&inny, 0xA5, sizeof(inny));
24memset(&outty, 0x2A, sizeof(outty));
25
26inny.a = 12;
27inny.b = 42;
28
29copyStruct = ^(MiniStruct aTinyStruct){ return aTinyStruct; }; // pass-by-value intrinsically copies the argument
30
31outty = copyStruct(inny);
32
33if ( &inny == &outty ) {
34printf("%s: struct wasn't copied.", argv[0]);
35exit(1);
36}
37if ( (inny.a != outty.a) || (inny.b != outty.b) ) {
38printf("%s: struct contents did not match.", argv[0]);
39exit(1);
40}
41
42printf("%s: success\n", argv[0]);
43return 0;
44}
45