poke-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

how to get the offset of the current struct


From: Bruno Haible
Subject: how to get the offset of the current struct
Date: Mon, 12 Feb 2024 00:27:09 +0100

Hi,

In some poke struct, for the _print function, I needed to get the offset of
the current struct:

type ABXML_string_pool =
  struct
  {
    // String pool header:
    uint<16> string_pool_type;
    ...

    method _print = void:
    {
      var my_offset = /*** HOW ***/;
      ...
    }
  }

What did not work:
  this'offset                 because this is not known
  string_pool_type'offset     because string_pool_type is an integer

What did work: Adding a zero-sized array the beginning:

type ABXML_string_pool =
  struct
  {
    uint<8>[0] struct_start;
    // String pool header:
    uint<16> string_pool_type;
    ...

    method _print = void:
    {
      var my_offset = struct_start'offset;
      ...
    }
  }

But this feels like a bad workaround. There should be a better way in the Poke
language. Is there?

Bruno






reply via email to

[Prev in Thread] Current Thread [Next in Thread]