github.com/razvanm/vanadium-go-1.3@v0.0.0-20160721203343-4a65068e5915/misc/cgo/testcdefs/main.c (about)

     1  // Copyright 2013 The Go Authors.  All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  #include "runtime.h"
     6  #include "cdefstest.h"
     7  
     8  void runtime·printf(int8*, ...);
     9  
    10  // From cdefstest.go.
    11  typedef struct CdefsOrig CdefsOrig;
    12  struct CdefsOrig {
    13  	int8 array1[20];
    14  	int8 array2[20][20];
    15  	int8 *array3[20];
    16  	int8 *array4[20][20];
    17  	int8 **array5[20][20];
    18  };
    19  
    20  // Packed structs are no longer supported for -cdefs.
    21  /*
    22  typedef struct PackedOrig PackedOrig;
    23  #pragma pack on
    24  struct PackedOrig {
    25  	int8 first;
    26  	int32 second;
    27  	int64 third;
    28  };
    29  #pragma pack off
    30  */
    31  
    32  void
    33  main·test(int32 ret)
    34  {
    35  	CdefsOrig o;
    36  	CdefsTest t;
    37  	// PackedOrig po;
    38  	// PackedTest pt;
    39  	
    40  	ret = 0;
    41  	if(sizeof(t.array1) != sizeof(o.array1) || offsetof(CdefsTest, array1[0]) != offsetof(CdefsOrig, array1[0])) {
    42  		runtime·printf("array1: size, offset = %d, %d, want %d, %d\n", sizeof(t.array1), offsetof(CdefsTest, array1[0]), sizeof(o.array1), offsetof(CdefsOrig, array1[0]));
    43  		ret = 1;
    44  	}
    45  	if(sizeof(t.array2) != sizeof(o.array2) || offsetof(CdefsTest, array2[0][0]) != offsetof(CdefsOrig, array2[0][0])) {
    46  		runtime·printf("array2: size, offset = %d, %d, want %d, %d\n", sizeof(t.array2), offsetof(CdefsTest, array2[0][0]), sizeof(o.array2), offsetof(CdefsOrig, array2[0][0]));
    47  		ret = 1;
    48  	}
    49  	if(sizeof(t.array3) != sizeof(o.array3) || offsetof(CdefsTest, array3[0]) != offsetof(CdefsOrig, array3[0])) {
    50  		runtime·printf("array3: size, offset = %d, %d, want %d, %d\n", sizeof(t.array3), offsetof(CdefsTest, array3[0]), sizeof(o.array3), offsetof(CdefsOrig, array3[0]));
    51  		ret = 1;
    52  	}
    53  	if(sizeof(t.array4) != sizeof(o.array4) || offsetof(CdefsTest, array4[0][0]) != offsetof(CdefsOrig, array4[0][0])) {
    54  		runtime·printf("array4: size, offset = %d, %d, want %d, %d\n", sizeof(t.array4), offsetof(CdefsTest, array4[0][0]), sizeof(o.array4), offsetof(CdefsOrig, array4[0][0]));
    55  		ret = 1;
    56  	}
    57  	if(sizeof(t.array5) != sizeof(o.array5) || offsetof(CdefsTest, array5[0][0]) != offsetof(CdefsOrig, array5[0][0])) {
    58  		runtime·printf("array5: size, offset = %d, %d, want %d, %d\n", sizeof(t.array5), offsetof(CdefsTest, array5[0][0]), sizeof(o.array5), offsetof(CdefsOrig, array5[0][0]));
    59  		ret = 1;
    60  	}
    61  /*
    62  	if(sizeof(pt.first) != sizeof(po.first) || offsetof(PackedTest, first) != offsetof(PackedOrig, first)) {
    63  		runtime·printf("first: size, offset = %d, %d, want %d, %d\n", sizeof(pt.first), offsetof(PackedTest, first), sizeof(po.first), offsetof(PackedOrig, first));
    64  		ret = 1;
    65  	}
    66  	if(sizeof(pt.second) != sizeof(po.second) || offsetof(PackedTest, second) != offsetof(PackedOrig, second)) {
    67  		runtime·printf("second: size, offset = %d, %d, want %d, %d\n", sizeof(pt.second), offsetof(PackedTest, second), sizeof(po.second), offsetof(PackedOrig, second));
    68  		ret = 1;
    69  	}
    70  	if(sizeof(pt.third) != sizeof(po.third) || offsetof(PackedTest, third) != offsetof(PackedOrig, third)) {
    71  		runtime·printf("third: size, offset = %d, %d, want %d, %d\n", sizeof(pt.third), offsetof(PackedTest, third), sizeof(po.third), offsetof(PackedOrig, third));
    72  		ret = 1;
    73  	}
    74  */
    75  	FLUSH(&ret); // flush return value
    76  }