github.com/spotify/syslog-redirector-golang@v0.0.0-20140320174030-4859f03d829a/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 void 21 main·test(int32 ret) 22 { 23 CdefsOrig o; 24 CdefsTest t; 25 26 ret = 0; 27 if(sizeof(t.array1) != sizeof(o.array1) || offsetof(CdefsTest, array1[0]) != offsetof(CdefsOrig, array1[0])) { 28 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])); 29 ret = 1; 30 } 31 if(sizeof(t.array2) != sizeof(o.array2) || offsetof(CdefsTest, array2[0][0]) != offsetof(CdefsOrig, array2[0][0])) { 32 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])); 33 ret = 1; 34 } 35 if(sizeof(t.array3) != sizeof(o.array3) || offsetof(CdefsTest, array3[0]) != offsetof(CdefsOrig, array3[0])) { 36 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])); 37 ret = 1; 38 } 39 if(sizeof(t.array4) != sizeof(o.array4) || offsetof(CdefsTest, array4[0][0]) != offsetof(CdefsOrig, array4[0][0])) { 40 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])); 41 ret = 1; 42 } 43 if(sizeof(t.array5) != sizeof(o.array5) || offsetof(CdefsTest, array5[0][0]) != offsetof(CdefsOrig, array5[0][0])) { 44 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])); 45 ret = 1; 46 } 47 FLUSH(&ret); // flush return value 48 }