03-04-2005, 05:09 PM
all union members have same address in memory, and the entire lenght in bytes of the union is the size of it's biggest field. It helps to save memory. Also modifying one you change the value of all members.
Code:
UNION MyUnion
i AS UINTEGER
s AS STRING * 1
b AS UBYTE
END UNION
DIM u AS MyUnion
PRINT "Lenght of the union in bytes:"; LEN(u)
print "Before u.i=2400:"
print "u.i = "; u.i
print "u.s = "; u.s
print "u.b = "; u.b
u.i=2400
print "After u.i=2400:"
print "u.i = "; u.i
print "u.s = "; u.s
print "u.b = "; u.b
print "Addresses of the union members:"
print "u.i = "; @u.i
print "u.s = "; @u.s
print "u.b = "; @u.b
SLEEP
url]http://fbide.sourceforge.net/[/url]