Page 1 of 1

Posted: Fri May 10, 2002 10:05 am
by BackupUser
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.

Posted: Fri May 10, 2002 11:33 am
by BackupUser
Restored from previous forum. Originally posted by Pupil.
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
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:

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)
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 :wink:

Posted: Fri May 10, 2002 12:12 pm
by BackupUser
Restored from previous forum. Originally posted by freak.

that makes sense , thanks.

--

A debugged program is one for which you have not yet found the conditions that make it fail.