blob: 5e613c79e7f16f8569c0e84cf51d3bfa8f5f48ee [file] [log] [blame]
Kevin Kluesf7dfeea2013-07-24 17:27:42 -07001// 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// +build ignore
6
7package cgotest
8
9/*
10// This file tests a bug found in the cgo -cdefs tool that incorrectly
11// translated Go pointer arrays generated by the cgo godefs tool back into C
12// pointer arrays.
13//
14// The comments below show how the type is translated from gcc-style C into Go
15// and back into C for both the buggy version and the correct version
16
17struct cdefsTest {
18 // This was already being handled correctly
19 // Correct: -> Array [20]int8 -> int8 array[20]
20 char array1[20];
21
22 // Buggy: -> Array [20][20]int8 -> [20]int8 array[20]
23 // Correct: -> Array [20][20]int8 -> int8 array[20][20]
24 char array2[20][20];
25
26 // Buggy: -> Array [20]*int8 -> *int8 array[20]
27 // Correct: -> Array [20]*int8 -> int8 *array[20]
28 char *array3[20];
29
30 // Buggy: -> Array [20][20]*int8 -> [20]*int8 array[20]
31 // Correct: -> Array [20]**int8 -> int8 *array[20][20]
32 char *array4[20][20];
33
34 // Buggy: -> Array [20][20]**int8 -> [20]**int8 array[20]
35 // Correct: -> Array [20][20]**int8 -> int8 **array[20][20]
36 char **array5[20][20];
37};
Matthew Dempskyf7a8adb2014-08-05 18:12:32 -070038
39// Test that packed structures can be translated to C correctly too.
40// See issue 8477.
41
42struct packedTest {
43 char first;
44 int second;
45 long long third;
46} __attribute__((packed));
47
48// Test that conflicting type definitions don't cause problems with cgo.
49// See issue 8477.
50
51typedef struct timespec {
52 double bogus;
53} pid_t;
54
Kevin Kluesf7dfeea2013-07-24 17:27:42 -070055*/
56import "C"
57
58type CdefsTest C.struct_cdefsTest
Ian Lance Taylor709096f2014-08-31 22:59:43 -040059
60//type PackedTest C.struct_packedTest