File: reftest.5c

package info (click to toggle)
nickle 2.107
  • links: PTS
  • area: main
  • in suites: forky, sid
  • size: 3,756 kB
  • sloc: ansic: 27,954; yacc: 1,874; lex: 954; sh: 204; makefile: 13; lisp: 1
file content (50 lines) | stat: -rw-r--r-- 664 bytes parent folder | download | duplicates (11)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
/*
 * Test various pointer and reference type combinations
 */

exception bad_result (poly a, poly b);

int i = 7;
string s = "hi";

&int ir = &i;

i = 8;

/* make sure references see changes to the underlying object */
if (i != ir)
    raise bad_result (i, ir);

*int ip = &i;

i = 9;

/* make sure pointers see changes to the underlying object */
if (i != *ip)
    raise bad_result (i, *ip);

if (ir != *ip)
    raise bad_result (ir, *ip);

/*
 * Make sure function return values typecheck correctly
 */
typedef s;
typedef struct {
    &s x;
} s;


s u() {
    s v;

    &v.x = reference(u());
    return v;
}

s t() {
    s v;

    &v.x = &t();
    return v;
}