github.com/razvanm/vanadium-go-1.3@v0.0.0-20160721203343-4a65068e5915/test/ken/ptrvar.go (about)

     1  // run
     2  
     3  // Copyright 2009 The Go Authors. All rights reserved.
     4  // Use of this source code is governed by a BSD-style
     5  // license that can be found in the LICENSE file.
     6  
     7  // Test pointers and the . (selector) operator on structs.
     8  
     9  package main
    10  
    11  type	x2	struct { a,b,c int; d int; };
    12  var	g1	x2;
    13  var	g2	struct { a,b,c int; d x2; };
    14  
    15  func
    16  main() {
    17  	var x int;
    18  	var s1 *x2;
    19  	var s2 *struct { a,b,c int; d x2; };
    20  
    21  	s1 = &g1;
    22  	s2 = &g2;
    23  
    24  	s1.a = 1;
    25  	s1.b = 2;
    26  	s1.c = 3;
    27  	s1.d = 5;
    28  
    29  	s2.a = 7;
    30  	s2.b = 11;
    31  	s2.c = 13;
    32  	s2.d.a = 17;
    33  	s2.d.b = 19;
    34  	s2.d.c = 23;
    35  	s2.d.d = 20;
    36  
    37  	if(s2.d.c != 23) { panic(1); }
    38  	if(g2.d.c != 23) { panic(2); }
    39  
    40  	x =	s1.a +
    41  		s1.b +
    42  		s1.c +
    43  		s1.d +
    44  
    45  		s2.a +
    46  		s2.b +
    47  		s2.c +
    48  		s2.d.a +
    49  		s2.d.b +
    50  		s2.d.c +
    51  		s2.d.d;
    52  
    53  	if(x != 121) { panic(x); }
    54  }