brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.1 KiB · 618a172 Raw
45 lines · c
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-exception5 6//  -*- mode:C; c-basic-offset:4; tab-width:4; intent-tabs-mode:nil;  -*-7// CONFIG8 9#import <stdio.h>10#import <stdlib.h>11#import <string.h>12 13typedef struct {14  int a;15  int b;16} MiniStruct;17 18int main (int argc, const char * argv[]) {19    MiniStruct inny;20    MiniStruct outty;21    MiniStruct (^copyStruct)(MiniStruct);22    23    memset(&inny, 0xA5, sizeof(inny));24    memset(&outty, 0x2A, sizeof(outty));    25    26    inny.a = 12;27    inny.b = 42;28 29    copyStruct = ^(MiniStruct aTinyStruct){ return aTinyStruct; };  // pass-by-value intrinsically copies the argument30    31    outty = copyStruct(inny);32 33    if ( &inny == &outty ) {34        printf("%s: struct wasn't copied.", argv[0]);35        exit(1);36    }37    if ( (inny.a != outty.a) || (inny.b != outty.b) ) {38        printf("%s: struct contents did not match.", argv[0]);39        exit(1);40    }41    42    printf("%s: success\n", argv[0]);43    return 0;44}45