File: varredef

package info (click to toggle)
tcng 10b-1
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 3,632 kB
  • ctags: 2,515
  • sloc: ansic: 19,038; pascal: 4,640; yacc: 2,619; sh: 1,908; perl: 1,546; lex: 772; makefile: 755
file content (112 lines) | stat: -rw-r--r-- 1,978 bytes parent folder | download | duplicates (5)
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
# can re-define global variables ----------------------------------------------
tcc -c -u stderr 2>&1
$a = 1;
$a = 2;
EOF
<stdin>:1: warning: unused variable a
<stdin>:2: warning: unused variable a
$a = 1
$a = 2
# can re-define used global variables -----------------------------------------
tcc -c -u stderr 2>&1
$a = 1;
$b = $a+1;
$a = 2;
EOF
<stdin>:3: warning: unused variable a
<stdin>:2: warning: unused variable b
$a = 1
$b = 2
$a = 2
# can re-define local variables -----------------------------------------------
tcc -c -u stderr -Wnounused 2>&1
prio {
    $a = 1;
    $a = 2;
}
EOF
{ device eth0
{ qdisc eth0:1
$a = 1
$a = 2
}
}
# local variable does not re-define global ------------------------------------
tcc -c -u stderr -Wnounused 2>&1
$a = 1;
eth5 {
    $a = 2;
    fifo;
}
EOF
$a = 1
{ device eth5
$a = 2
}
# re-defined local variable does not re-define global -------------------------
tcc -c -u stderr -Wnounused 2>&1
$x = 1;
eth1 {
   $x = 2;
   $x = 3;
   fifo;
}
EOF
$x = 1
{ device eth1
$x = 2
$x = 3
}
# -Wredefine reports global re-definition -------------------------------------
tcc -c -u stderr 2>&1
warn "unused","redefine";

$y = 1;
$y = 2;
EOF
<stdin>:3: warning: unused variable y
<stdin>:4: warning: variable y redefined
<stdin>:4: warning: unused variable y
$y = 1
$y = 2
# -Wredefine reports local re-definition --------------------------------------
tcc -c -u stderr -Wnounused -Wredefine 2>&1
dsmark {
    $z = 1;
    $z = 2;
    fifo;
}
EOF
<stdin>:3: warning: variable z redefined
{ device eth0
{ qdisc eth0:1
$z = 1
$z = 2
{ class eth0:1:0
}
}
}
# -Wredefine does not report local vs. global ---------------------------------
tcc -c -u stderr -Wnounused -Wredefine 2>&1
$c = 0;
eth1 {
    $c = 1;
    fifo;
}
EOF
$c = 0
{ device eth1
$c = 1
}
# variables and devices: variable right after device is okay ------------------
tcc -c -u stderr -Wnounused 2>&1
$foo = 1;
eth0 {
    $foo = 2;
    fifo;
}
EOF
$foo = 1
{ device eth0
$foo = 2
}