05-03-2005, 11:57 AM
Downloaded the 0.13b version of FB and have been playing around with pointers a little. Some of this is very nitpicky because most programmers are unlikely to use the expressions I am using. Also due to the lack of available documentation on FB currently, Im going mostly by C's semantics of pointers, so correct me if Im wrong on anything.
Are unary operators actually part of expressions? Im often getting: "error(9): Expected expression, found : 'something' ", when doing less than normal things with the unary * and @ operators, this is most notable here:
When both the unary * and @ operators are used together, they should nullify the effect.
Is pointer arithmetic meant to be commutative?
Why are you allowed to add two pointers together using pointer arithmetic?
This compiles fine, but segfaults (Annoying report your problem to Microsoft box) when run.
Do the unary @ and * operators have the same precedence? Why does this successfully compile?
This compiles, and prints the same value for p, dp and @a. The expression: '*@(@dp)' should be equivalent to '@dp' in which case p and dp would have different values. The expression in the above code snippet shouldn't compile at all, because it doesn't make sense to take the address of an address. Note that replacing '*@(@dp)' with '*(@dp)' will give the same results (p, dp and @a all have the same value).
Are unary operators actually part of expressions? Im often getting: "error(9): Expected expression, found : 'something' ", when doing less than normal things with the unary * and @ operators, this is most notable here:
Code:
dim p as integer pointer, a as integer
p = @a ' This works fine
p = @(a) ' This produces an error
When both the unary * and @ operators are used together, they should nullify the effect.
Code:
dim a as integer, b as integer, p as integer pointer
b = 10
a = *@b ' This works correctly, a is assigned the value 10
p = @*p ' Gives error 9, with expecting expression, found *
Is pointer arithmetic meant to be commutative?
Code:
dim p as integer pointer, i as integer
dim array(0 to 5) as integer
p = @array(0)
for i = 0 to 5
*(p + i) = i 'This works
*(i + p) = i 'This doesn't: Error(70): Incomplete type before ')'
next
Why are you allowed to add two pointers together using pointer arithmetic?
Code:
dim p as integer pointer, i as integer
dim array(0 to 5) as integer
p = @array(0)
*(p + p) = 10
Do the unary @ and * operators have the same precedence? Why does this successfully compile?
Code:
dim p as integer pointer, dp as integer pointer pointer
dim a as integer
dp = &a
p = *@(@dp)
print "p = "; p ;", dp = "; dp ;"@a = "; @a