【问题标题】:How to convert C struct with union inside to Delphi [duplicate]如何将内部带有联合的C结构转换为Delphi [重复]
【发布时间】:2014-10-08 20:49:13
【问题描述】:

对于将下一个 C 结构转换为 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];
   };
};

我已经阅读了 Rudy 关于转换 http://rvelthuis.de/articles/articles-convert.html 的文章,但仍然不知道如何处理联合内的匿名结构。

感谢任何帮助或建议。

【问题讨论】:

  • 在这种情况下你很幸运,无需担心 Delphi 中缺少匿名联合。所有变体成员都在 struct 的末尾,因此翻译非常简单。
  • FWIW,我在这里解释一下:Pitfalls of converting.

标签: c delphi struct


【解决方案1】:

使用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;

【讨论】:

  • float 是单精度,除非特别重新定义。
  • 这很容易......谢谢!
猜你喜欢
  • 1970-01-01
  • 2017-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-06-27
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多