This union structure seems hard to convert to pascal record using case of.
Title: Re: How C++ union to Pascal?
Post by: Handoko on January 28, 2020, 08:18:09 am
Maybe record with variable part: https://wiki.freepascal.org/Record#Variable_structure (https://wiki.freepascal.org/Record#Variable_structure)
I'm not familiar with this topic but I think you can learn more from this discussion: https://forum.lazarus.freepascal.org/index.php/topic,45832.msg324601.html#msg324601 (https://forum.lazarus.freepascal.org/index.php/topic,45832.msg324601.html#msg324601)
Title: Re: How C++ union to Pascal?
Post by: wytwyt02 on January 28, 2020, 08:24:17 am
the size of c++ union - translated record is size of biggest member.
Title: Re: How C++ union to Pascal?
Post by: Handoko on January 28, 2020, 08:45:57 am
@wytwyt02
I usually avoid record with variable part, it seems a bit too hard for me to digest. For simple cases, I usually use absolute.
https://wiki.lazarus.freepascal.org/Absolute
Title: Re: How C++ union to Pascal?
Post by: Thaddy on January 28, 2020, 08:47:19 am
@JernejL Correct. That is the same as a C union. We call that a variant record in Pascal speak (nothing to do with variants) https://www.freepascal.org/docs-html/ref/refsu15.html
Title: Re: How C++ union to Pascal?
Post by: PascalDragon on January 28, 2020, 09:30:28 am
Title: Re: How C++ union to Pascal?
Post by: JernejL on January 28, 2020, 11:16:02 am
if there are multiple nested unions it is simply best to split them into separate packed records.
Title: Re: How C++ union to Pascal?
Post by: syntonica on January 29, 2020, 03:21:39 pm
Record casting also works quite nicely. Define two equal-sized records with different field structures. I didn't know about "absolute" though. That may be a better solution. I rarely work with unions.