SHOW:
|
|
- or go back to the newest paste.
1 | - | #include "crt.bi" |
1 | + | type x |
2 | x as long | |
3 | - | type Point |
3 | + | |
4 | - | as long x |
4 | + | |
5 | - | as long y |
5 | + | |
6 | 'variable named "x", having "x" as type | |
7 | 'this is fine since despite having the same names they are not used in the same contexts | |
8 | - | function createPoint( x as long , y as long) as point |
8 | + | dim shared as x x |
9 | - | dim as point p |
9 | + | dim shared as long y |
10 | - | p.x = x |
10 | + | |
11 | - | p.y = y |
11 | + | sub MySub( x as long ) |
12 | - | return p |
12 | + | dim as integer y = 5 |
13 | - | end function |
13 | + | print "y=";y,".y=";.y |
14 | print "parm x=";x,"old x.x=";.x.x | |
15 | - | scope 'int main() { |
15 | + | .x.x = x |
16 | - | dim as Point myPoint = createPoint(3, 4) |
16 | + | print "parm x=";x,"new x.x=";.x.x |
17 | - | printf(!"Point coordinates: (%d, %d)\n", myPoint.x, myPoint.y) |
17 | + | end sub |
18 | - | |
18 | + | |
19 | - | dim as point MyPointToo = type(3,4) 'initialize the struct |
19 | + | scope 'main |
20 | - | with myPointToo 'can be used to simplify access to a struct |
20 | + | |
21 | - | printf(!"Point coordinates: (%d, %d)\n", .x, .y) |
21 | + | 'setting global x heres... |
22 | - | end with |
22 | + | y = 10 |
23 | - | |
23 | + | x.x = 12 |
24 | - | end 0'return 0 |
24 | + | |
25 | - | end scope '} |
25 | + | 'declared a "x" as string which is fine since this is a different scope |
26 | - | |
26 | + | dim as string x = "hello world" |
27 | ||
28 | 'freebasic kinda screwed up in this case... because sizeof() should refer to type X as priority | |
29 | 'and len(x) should refer to variable x.. as priority.... but they don't | |
30 | print "sizeof(x)=";sizeof(x) 'this will cause a warn due to ambiguity (and will show the size of the struct) | |
31 | print "len(x)=";len(x) 'this will cause a warn due to ambiguity (and will show the size of the struct) | |
32 | ||
33 | print sizeof(.x) 'this will NOT WARN and show the size of the struct | |
34 | print sizeof(..x) 'this will NOT WARN and show the size of the struct | |
35 | print sizeof(*@x) 'this will NOT WARN and show the size of the variable (12 since that's the size of the string descriptor) | |
36 | print len(*@x) 'this will NOT WARN and show the LENGTH of the string variable | |
37 | ||
38 | MySub(15) | |
39 | sleep | |
40 | end scope |