Restored from previous forum. Originally posted by freak.
Hi all,
I just found the StructureUnion command in the Docs, and I don't understand it's use.
What does 'sharing some fields inside the same structure' mean?
What does this Command do?
I don't know C/C++ so I don't know the command from there.
Can somebody please give me a hint??
Thanks,
Timo
--
A debugged program is one for which you have not yet found the conditions that make it fail.
StructureUnion?
-
BackupUser
- PureBasic Guru

- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
Restored from previous forum. Originally posted by Pupil.
As you can see when running this example the structure 'testtype1' is smaller than 'testtype2' what has happened is that the types inside the union declaration is located on the same memory address which means that you can either store a long word, a floatingpoint value or a pointer to a string but not more than one those at a time. In the other structure however you can store all those different types at the same time.
Hope that helped a bit, pardon my bad explanation skills
I think it means that you can use the same 'memory spot' in a structure to access diffrerent types of data. Consider this little example:Hi all,
I just found the StructureUnion command in the Docs, and I don't understand it's use.
What does 'sharing some fields inside the same structure' mean?
What does this Command do?
I don't know C/C++ so I don't know the command from there.
Can somebody please give me a hint??
Thanks,
Timo
Code: Select all
Structure testtype1
a.l
StructureUnion
b.l
c.f
d.s
EndStructureUnion
EndStructure
Structure testtype2
a.l
b.l
c.f
d.s
EndStructure
msg.s = "size 'testtype1'="+Str(SizeOf(testtype1))+Chr(10)
msg + "size 'testtype2'="+Str(SizeOf(testtype2))
MessageRequester("", msg, 0)
Hope that helped a bit, pardon my bad explanation skills
-
BackupUser
- PureBasic Guru

- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm