converting C headers to pas files lazarus / 33-macOS - Mac OS X ---------------------------------------------------------------------- inferno · 2019-11-26 13:18 Hi all, I'm trying to convert C headers with the structures as follow: Code: C  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i typedef struct {#define KAUTH_GUID_SIZE 16      /* 128-bit identifier */      unsigned char g_guid[KAUTH_GUID_SIZE];} guid_t; struct _acl_entry {      u_int32_t       ae_magic;#define _ACL_ENTRY_MAGIC        0xac1ac101        u_int32_t       ae_tag;        guid_t          ae_applicable;        u_int32_t       ae_flags;        u_int32_t     ae_perms;}; struct _acl {        u_int32_t       a_magic;#define _ACL_ACL_MAGIC          0xac1ac102        unsigned        a_entries;      int             a_last_get;        u_int32_t       a_flags;      struct _acl_entry a_ace[ACL_MAX_ENTRIES];}; The pascal versions below. I don't know what to do with const values and also not sure about types conversion... Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i guid_t = packed record    KAUTH_GUID_SIZE: Integer; //const = 16    g_guid: array[0..(KAUTH_GUID_SIZE)-1] of byte;end; _acl_entry = packed record    ae_magic: dword;    _ACL_ENTRY_MAGIC: Cardinal; //const = $ac1ac101    ae_tag: dword;    ae_applicable: guid_t;    ae_flags: dword;    ae_perms: dword; end;  _acl = packed record    a_magic: dword;    _ACL_ENTRY_MAGIC: Cardinal; //const = $ac1ac102    a_entries: Cardinal;    a_last_get: Integer;    a_flags: dword;    a_ace: array[0..(ACL_MAX_ENTRIES)-1] of _acl_entry; end; Any suggestions? Best regards, Inferno ---------------------------------------------------------------------- 440bx · 2019-11-26 13:38 Quote from: inferno on November 26, 2019, 02:18:55 pmI don't know what to do with const values and also not sure about types conversion... All you need to do is convert the #define(s) to Pascal const(s), for those you showed:Code: C  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i #define KAUTH_GUID_SIZE 16      /* 128-bit identifier */#define _ACL_ENTRY_MAGIC        0xac1ac101#define _ACL_ACL_MAGIC          0xac1ac102 the equivalent Pascal version is:Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i const  KAUTH_GUID_SIZE   = 16;  _ACL_ENTRY_MAGIC  = $ac1ac101;  _ACL_ACL_MAGIC    = $ac1ac102; That's all there is to it. Also, get rid of the declarations you currently have for those #define(s).  The way you have them now makes them fields of the record and they are _not_ fields of those records, they are simply constant declarations. HTH. ---------------------------------------------------------------------- inferno · 2019-11-26 16:45 Thank you 440bx! How about type conversions - are they correct (u_int32_t -> dword, unsigned -> cardinal, int -> integer)? Best regards, Inferno ---------------------------------------------------------------------- lucamar · 2019-11-26 17:38 Quote from: inferno on November 26, 2019, 05:45:21 pmHow about type conversions - are they correct (u_int32_t -> dword, unsigned -> cardinal, int -> integer)? They are correct but note that there are aliases in the system unit which were added, IIRC, precisely to ease this kind of conversions: Int8, UInt8, Int16, UInt16, Int32, UInt32, Int64, UInt64, an its corresponding pointers: PInt8, PUInt8, PInt16, etc. They are described in the help for that unit (in the RTL help). ---------------------------------------------------------------------- marcov · 2019-11-26 19:02 Somewhat older is unit ctypes, it defines many C types for use in headers, prefixed with a "C" https://www.freepascal.org/docs-html/current/rtl/ctypes/index-3.html ---------------------------------------------------------------------- inferno · 2019-12-02 14:26 Thanks lucamar and marcov! I got it working. On macOS there is the useful unit MacTypes - maybe it will be useful for somebody. Best regards, Inferno