1

I'd appreciate any help with converting next C-structure to Delphi

struct MATRIX
{
   union
   {
       struct
       {
        float _11, _12, _13, _14;
        float _21, _22, _23, _24;
        float _31, _32, _33, _34;
        float _41, _42, _43, _44;
       };
       float m[4][4];
   };
};

I've read Rudy's article about converting http://rvelthuis.de/articles/articles-convert.html but still can't figure out what to do with anonymous struct inside the union..

Thanks for any help or recommendations.

niosik
  • 11
  • 1
  • 2
  • In this case you are lucky, there is no need to worry about anonymous union missing from Delphi. All the variant members are at the end of struct, so the translation is pretty straightforward. – Free Consulting Oct 08 '14 at 21:59
  • Just FWIW, I explain this here: [Pitfalls of converting](http://rvelthuis.de/articles/articles-convert.html#unions). – Rudy Velthuis Oct 10 '14 at 09:24

1 Answers1

4

Use a variant record:

type
  Matrix = record
    case boolean of
    false: (_11,_12,_13,_14,
            _21,_22,_23,_24,
            _31,_32,_33,_34,
            _41,_42,_43,_44: Single);
    true: (m: array[0..3,0..3] of Single);
  end;
David Heffernan
  • 601,492
  • 42
  • 1,072
  • 1,490
LU RD
  • 34,438
  • 5
  • 88
  • 296