[futurebasic] Re: [FB] Replacing semicolon syntax in records

Message: < previous - next > : Reply : Subscribe : Cleanse
Home   : October 2007 : Group Archive : Group : All Groups

From: Robert Purves <listrp@...>
Date: Sun, 14 Oct 2007 22:46:17 +1300
Bernie wrote:

> '------------
> begin record TestRecUnion
> dim as short vert, horz
> end record
>
> begin record TestRec
> dim as long dummy
> begin union
> dim as Point myPoint
> dim as TestRecUnion u
> end union
> end record
>
> dim as TestRec info
>
> info.myPoint.h% = 100
> info.myPoint.v% = 200
>
> print info.myPoint.h%,info.myPoint.v%
> print info.u.horz,info.u.vert
> '------------
>
>
> Questions:
>
> [1] Are there any pitfalls to this approach (endian issues)?

No, but this has an endian bug:

begin record BadUnion
dim as short highWord, lowWord
end record

begin record BadRec
begin union
dim as long myLong
dim as BadUnion u
end union
end record

dim as BadRec myBadRec
myBadRec.myLong = 12345678
print myBadRec.u.highWord, myBadRec.u.lowWord



> [2] Is there a better way?

Yes. Abolish the aliased variables vert and horz. This is better code:

begin record TestRec
dim as long dummy
dim as Point myPoint
end record

dim as TestRec info

info.myPoint.h% = 100
info.myPoint.v% = 200

print info.myPoint.h%, info.myPoint.v%


Robert P.