In your above example, the nested unnamed TYPE is useless because it contains only one element.
yes I was only playing with syntax. The goal of the test is both:
- verifying that whatever switchable field within the union (unionable field?) is used, the address is always unique, and
- observing that when I change the size of the array of bytes of any of the 2 switchable, the size of the union is also unique and equal to the greatest possible size
About the new version proposal, it's very fine and of you to have made it so fast. It's very more accurate than the previous paragraph. I have made some changes below to show how I see things that I still feel a bit difficult to guess with 100% certainty, or that I just do not understand at all.
fxm wrote:UNION description update proposal
Unions are similar to a Type structure, except that
the elements of a union occupy a common space in memory (same memory address for all elements of the union).
The size of the Union is the size of the largest data item.
A data item can be an unnamed Type.
Since they occupy a common memory space, only one element can usually be used at a given time.
--> maybe better add a sentence to say what is in a union rather than adding this with the 'global' size description?
[Unions share characteristics with user defined types, and also have differences.]
[*]LikeUser Defined Type, Union can use the optional Field = number specifier ---> I dont see what this means (that the fields can have default values?)
and supports also inheritance through the use of the Extends keyword.
[*]Unlike User Defined Types, Union can not contain variable-length strings and arrays, and more generally fields
(or can not have bases)with constructors or destructors (or can not have bases...-->?). Therefore, Union does not support to inherit from the Object built-in type. (maybe a link to Object page here?) The size of the Union is the size of the largest data item. A data item can be an unnamed Type. Since they occupy [s]the samea common memory space, only one element can usually ??be used at a given time.[/s]
Unions support member procedures including Constructor, Destructor, Function, Operator, Property and Sub. All members of a union are public and
access controlaccess modifiers are isnot supported.
Nested unnamed type or union
cannotcan NOT have procedure members or static data members (same restriction for local ->meaning?? named type/union).
A Union can be passed
asin a similar way of a user defined type to overloaded operator functionsprocedures.
This part below is not too much clear. Maybe it should be put not as a simple not, but as a paragraph about inheritance and unions. Or, a link to a dedicated place in the inheritance page, so it could come with examples and details that would make it perfectly sound.
fxm wrote:Note: When Union extends a base type, it can be confusing because no new fields are added to the base, but instead the base is added to the derived Union. This means that fields in the derived Union can share the same memory space like the base (here it doesn't matter whether the base is a Union or not). Of course it can be dangerous, but that is always the problem with Unions.
If only the base is a Union, then it won't be affected by fields from the derived UDT.
Since Union is not allowed to have complex fields (i.e. UDTs with constructor/destructor, or dynamic strings), a derived Union cannot be allowed to have (contain) a complex base.
And to finish, I would like to know if those 2 sentences below are true. If they are true could something like this be said along the introductory text, because it is one of the difficult point with unions: how to write them.
The Union is a group of data that can take 2 forms, either the form of a single data field or, the form of a group of data types embedded in a nested Type bloc.
Only one data member, either as a single data field or as a complex data field group within a Type bloc, can be used at a given time. When a given data field is written, the other data fields sharing the common union space may be overwritten or mutilated.
Nested type blocs in the context of Union are not user defined types, they are just blocs gathering data together.