swap syntax error

General FreeBASIC programming questions.
Hard
Posts: 135
Joined: Aug 29, 2008 21:13

swap syntax error

Postby Hard » Sep 17, 2009 0:10

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

Re: swap syntax error

Postby Zippy » Sep 17, 2009 0:30

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

Postby nobozoz » Sep 17, 2009 2:54

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: 5317
Joined: May 27, 2005 6:42
Location: Illinois
Contact:

Postby cha0s » Sep 17, 2009 7:09

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

Postby Hard » Sep 17, 2009 10:56

Image
cha0s
Site Admin
Posts: 5317
Joined: May 27, 2005 6:42
Location: Illinois
Contact:

Postby cha0s » Sep 17, 2009 21:20

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

Postby Hard » Sep 17, 2009 21:52

Image

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: 1156
Joined: May 08, 2006 21:58
Location: Crewe, England

Postby jevans4949 » Sep 17, 2009 22:09

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

Return to “General”

Who is online

Users browsing this forum: No registered users and 3 guests