<html>
<head>
<style><!--
.hmmessage P
{
margin:0px;
padding:0px
}
body.hmmessage
{
font-size: 10pt;
font-family:Tahoma
}
--></style>
</head>
<body class='hmmessage'>
construction various data?<br><br>So, I have this C:<br><br><br>typedef struct _enum_t {<br>  const char* name;<br>  uint64_t value;<br>} enum_t;<br><br>typedef struct _field_t {<br>    char name[16];<br>    uchar offset;<br>    uchar size;<br>    uchar element_size;<br>    uchar str;<br>    uchar macho_string;<br>    uchar enum_table_count;<br>    const enum_t* enum_table;<br>} field_t;<br><br>#define FIELD(t, f) {STRINGIZE(f), offsetof(t, f), sizeof((((t*)0)->f))}<br>#define FIELD_ARRAY(t, f) {STRINGIZE(f), offsetof(t, f), sizeof((((t*)0)->f)), sizeof((((t*)0)->f)[0]) }<br>#define FIELD_STRING(t, f) {STRINGIZE(f), offsetof(t, f), sizeof((((t*)0)->f)), sizeof((((t*)0)->f)[0]), 1 }<br>#define FIELD_ENUM(t, f, e) {STRINGIZE(f), offsetof(t, f), sizeof((((t*)0)->f)), 0, 0, 0, sizeof(e)/sizeof((e)[0]), e }<br>#define FIELD_MACHO_STRING(t, f) {STRINGIZE(f), offsetof(t, f), sizeof((((t*)0)->f)), 0, 0, 1 }<br><br>typedef struct _struct_t {<br>    const char* name;<br>    uint    size;<br>    uint    nfields;<br>    const field_t* fields;<br>    int widest_field;<br>} struct_t;<br><br>#define STRUCT(a) {STRINGIZE(a), sizeof(a), NUMBER_OF(PASTE(a,_fields)), PASTE(a,_fields)}<br><br>extern_const enum_t<br>macho_magic_names[] = {<br>    { "magic32", macho_magic32 },<br>    { "magic64", macho_magic64 }<br>};<br><br>extern_const enum_t<br>macho_cputype_names[] = {<br>    { "x86", macho_cpu_type_x86 },<br>    { "amd64", macho_cpu_type_amd64 },<br>    { "powerpc", macho_cpu_type_powerpc },<br>    { "powerpc64", macho_cpu_type_powerpc64 }<br>};<br><br>extern_const enum_t<br>macho_cpusubtype_names[] = {<br>    { "powerpc_all", macho_cpu_subtype_powerpc_all },<br>    { "x86_all", macho_cpu_subtype_x86_all }<br>};<br><br>extern_const enum_t<br>macho_filetype_names[] = {<br>    { "object", macho_type_object },<br>    { "execute", macho_type_execute },<br>    { "fixed_vm_library", macho_type_fixed_vm_library },<br>    { "core", macho_type_core },<br>    { "preload", macho_type_preload },<br>    { "dylib", macho_type_dylib },<br>    { "dylinker", macho_type_dylinker },<br>    { "bundle", macho_type_bundle },<br>    { "dylib_stub", macho_type_dylib_stub },<br>    { "dsym", macho_type_dsym } };<br>        <br>extern_const field_t<br>macho_header32_t_fields[] = {<br>    FIELD_ENUM(macho_header32_t, magic, macho_magic_names),<br>    FIELD_ENUM(macho_header32_t, cputype, macho_cputype_names),<br>    FIELD_ENUM(macho_header32_t, cpusubtype, macho_cpusubtype_names),<br>    FIELD_ENUM(macho_header32_t, filetype, macho_filetype_names),<br>    FIELD(macho_header32_t, ncmds),<br>    FIELD(macho_header32_t, sizeofcmds),<br>    FIELD(macho_header32_t, flags)<br>};<br><br><br>how do I "best" convert this to Modula-3?<br><br>I don't see a good analog to offsetof.<br>I don't see a good analog of variably sized non-copying arrays, esp. constants.<br>I have something kind of close, but I have to use VAR in places instead<br>of CONST, and I have to make copies of the arrays, and I have to compute<br>the offsets/sizes myself, which isn't difficult.<br><br><br>I understand that using offset of is necesssarily unsafe.<br><br>What I have, C and Modula-3, is checked in, in scratch/macho.<br><br><br>Thanks,<br> - Jay                                          </body>
</html>