Forum > General

Anonymous Unions-Middle Road variants in records.

(1/3) > >>

has there been any thought yet, for supporting anonymous records inside records so we can wrap it around a Variant in the middle of the base record?

  It's very difficult to translate anonymous C unions that reside before the end of the record/struct without adding a new name tag. Adding name tags makes a mess out of translating a large C/C++ code base, especially the types I deal with.

 Either FPC can have a UNION that behaves like a C UNIT or make a nameless record with a following CASE ... OF .. END that only is allowed within a starting record define.


That's more or less why I introduced OpaqueRecord and POpaqueRecord (system unit).
This should cover your C translations.

Seconded! Nameless records and case-of records not only at the end of the record.

And less RTTI!

Hope and change!  :)

I wanted to add that there is a way of doing this but it's very messy.

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---type  TUnion = Record    Case boolean of     True :(A:integer;      C:Integer); //Remainder of record here.     false:(B:integer); End;                               
If you look at this construct, A and B field live in the same space.
if you expand, lets say A to include more data, this extra data will actually be there following those A,B unions but C will live after those either way.
 This means that you need to build the remainder of the record like this, and that can even include another nested variant for which you extend any following more non-UNION fields in the same way

keep this up and it will look like a Tree.

 This mess only needs to be used if you have anonymous unions/variants, otherwise, you can wrap the variant with a named record type within or outside type.


[0] Message Index

[#] Next page

Go to full version