-
Notifications
You must be signed in to change notification settings - Fork 149
/
Copy pathfor-ptr.bas
94 lines (81 loc) · 2.12 KB
/
for-ptr.bas
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
# include "fbcunit.bi"
SUITE( fbc_tests.compound.for_ptr )
TEST( for_pointer_counter )
#macro buildTest( __TYPE__ )
scope
dim as __TYPE__ buff( 9 )
dim as __TYPE__ ptr iBuffer = @buff( 0 )
dim as integer c, stp
for i as integer = 0 to 9
iBuffer[i] = i
next
c = 0
for i as __TYPE__ ptr = iBuffer to iBuffer + 9
CU_ASSERT( *i = c )
CU_ASSERT( i = ( c + iBuffer ) )
c += 1
next
c = 9
for i as __TYPE__ ptr = iBuffer + 9 to iBuffer step -1
CU_ASSERT( *i = c )
CU_ASSERT( i = ( c + iBuffer ) )
c -= 1
next
c = 0
stp = 2
for i as __TYPE__ ptr = iBuffer + 9 to iBuffer step stp
CU_ASSERT( *i = c )
CU_ASSERT( i = ( c + iBuffer ) )
c += 2
next
end scope
#endmacro
buildTest( byte )
buildTest( short )
buildTest( single )
buildTest( double )
buildTest( longint )
type foo
as any ptr x, y
end type
dim as foo buff( 9 )
dim as foo ptr fBuffer = @buff( 0 )
dim as integer c
'' Fill the x/y fields in the buffer with their own addresses
for i as foo ptr = fBuffer to fBuffer + 9
i->x = i
i->y = i->x + offsetof( foo, y )
CU_ASSERT( i = ( fBuffer + c) )
c += 1
next
'' Check the fields against their addresses
dim as integer stp = 2
for i as foo ptr = fBuffer to fBuffer + 9 step stp
CU_ASSERT( i->x = @i->x )
CU_ASSERT( i->y = @i->y )
next
END_TEST
TEST( for_any_pointer )
dim as integer array(0 to 3)
for i as ubyte ptr = 0 to 3
CU_ASSERT( cint( i ) >= 0 )
CU_ASSERT( cint( i ) <= 3 )
array(cint( i )) = cint( i )
next
'' Any Ptr should be treated as Byte Ptr, as in BOP pointer arithmetic
for i as any ptr = 0 to 3
CU_ASSERT( cint( i ) >= 0 )
CU_ASSERT( cint( i ) <= 3 )
CU_ASSERT( array(cint( i )) = cint( i ) )
next
type foo as bar
'' Iterating on "foo ptr" isn't possible because sizeof( foo ) is
'' unknown, but "foo ptr ptr" should work because sizeof( foo ptr )
'' is known.
for i as foo ptr ptr = 0 to 3
CU_ASSERT( cint( i ) >= 0 )
CU_ASSERT( cint( i ) <= 3 )
CU_ASSERT( array(cint( i )) = cint( i ) )
next
END_TEST
END_SUITE