General FreeBASIC programming questions.
-
Hard
- Posts: 135
- Joined: Aug 29, 2008 21:13
Post
by Hard »
hi there
just a little question. is this how it was supposed to be:
Code: Select all
swap bla, blub 'works
swap(bla, blub) 'doesnt
thanks - hard
-
Zippy
- Posts: 1295
- Joined: Feb 10, 2006 18:05
Post
by Zippy »
Hard wrote:hi there
just a little question. is this how it was supposed to be:
Code: Select all
swap bla, blub 'works
swap(bla, blub) 'doesnt
thanks - hard
Yes.
-
nobozoz
- Posts: 238
- Joined: Nov 17, 2005 6:24
- Location: Chino Hills, CA, USA
Post
by nobozoz »
Hard,
As far as I can tell, 'Swap' is a direct pointer swap without any syntax checking by the compiler.
Code: Select all
Dim bla as integer = 7
Dim blub as double = 5.0
Print @bla,@blub,bla,blub
Swap bla, blub
Print @bla,@blub,bla,blub
'... etc
Don't know why you'd do this intentionally, but the results can be "interesting".
Jim
-
cha0s
- Site Admin
- Posts: 5319
- Joined: May 27, 2005 6:42
- Location: USA
-
Contact:
Post
by cha0s »
Could you print the output of your program, nobozoz? I'm still working on getting fbc to work here...
-
Hard
- Posts: 135
- Joined: Aug 29, 2008 21:13
Post
by Hard »
-
cha0s
- Site Admin
- Posts: 5319
- Joined: May 27, 2005 6:42
- Location: USA
-
Contact:
Post
by cha0s »
Oh crazy. Is this the same result you'd get as if you did:
Code: Select all
Dim blub As Double = 5.0
blub = *cast(integer ptr, @blub)
print blub
?
-
Hard
- Posts: 135
- Joined: Aug 29, 2008 21:13
Post
by Hard »
unnessesary to make a screeny here, but i didnt want to be a combo breaker :D
btw:
Code: Select all
DIM blub As DOUBLE = 5
blub = *cast(Integer Ptr, @blub)
Print blub '0
Code: Select all
DIM blub As INTEGER = 5
blub = *cast(Integer Ptr, @blub)
Print blub '5
-
jevans4949
- Posts: 1186
- Joined: May 08, 2006 21:58
- Location: Crewe, England
Post
by jevans4949 »
Hard wrote:btw: ...
Not surprising, since the business part of a double containing 5 is stored in memory at the highest address, and the lowest bits contain zeros.
Code: Select all
Union xx
d As Double
b(0 To 7) As UByte
End Union
Dim blub As xx
blub.d = 5
For i As Integer = 0 To 7
Print Hex(blub.b(i),2);
Next
Print
Sleep
EDIT: prints 0000000000001440