github.com/mdempsky/go@v0.0.0-20151201204031-5dd372bd1e70/misc/cgo/test/issue11925.go (about)

     1  // Copyright 2015 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  // Issue 11925.  Structs with zero-length trailing fields are now
     6  // padded by the Go compiler.
     7  
     8  package cgotest
     9  
    10  /*
    11  struct a11925 {
    12  	int i;
    13  	char a[0];
    14  	char b[0];
    15  };
    16  
    17  struct b11925 {
    18  	int i;
    19  	char a[0];
    20  	char b[];
    21  };
    22  */
    23  import "C"
    24  
    25  import (
    26  	"testing"
    27  	"unsafe"
    28  )
    29  
    30  func test11925(t *testing.T) {
    31  	if C.sizeof_struct_a11925 != unsafe.Sizeof(C.struct_a11925{}) {
    32  		t.Errorf("size of a changed: C %d, Go %d", C.sizeof_struct_a11925, unsafe.Sizeof(C.struct_a11925{}))
    33  	}
    34  	if C.sizeof_struct_b11925 != unsafe.Sizeof(C.struct_b11925{}) {
    35  		t.Errorf("size of b changed: C %d, Go %d", C.sizeof_struct_b11925, unsafe.Sizeof(C.struct_b11925{}))
    36  	}
    37  }