poke-devel
[Top][All Lists]
Advanced

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

Re: how to get the offset of the current struct


From: Jose E. Marchesi
Subject: Re: how to get the offset of the current struct
Date: Mon, 12 Feb 2024 01:15:00 +0100
User-agent: Gnus/5.13 (Gnus v5.13)

> Jose E. Marchesi wrote:
>> method _print = void:
>> {
>>   var my_offset = SELF'offset;
>>   var my_ios = SELF'ios;
>>   var name_of_first_field = SELF'ename (1);
>
> Thanks!
>
>> Any attribute that works for values of type `any' can be applied to
>> SELF.
>
> How about adding to the documentation
>   * in the concept index, an entry for SELF ?
>   * a subsection that lists all the attributes that apply to all types?
>     I'm navigating through the table of contents, and I found subsections
>       Integer Attributes
>       Offset Attributes
>       String Attributes
>       Array Attributes
>       Struct Attributes
>     but no section
>       General Type Attributes

I will do.  Thanks for the suggestions.

> Btw, I still need the zero-length array trick in another place:
>
> type ABXML_chunk =
>   struct
>   {
>     // Chunk header:
>     uint<16> chunk_type;
>     offset<uint<16>,B> chunk_header_size;
>     offset<uint<32>,B> chunk_size;
>
>     // Data:
>     uint<8>[0] before_bulk_of_data;
>     uint<8>[chunk_size - before_bulk_of_data'offset] data;
>   };
>
> works, whereas
>
> type ABXML_chunk =
>   struct
>   {
>     // Chunk header:
>     uint<16> chunk_type;
>     offset<uint<16>,B> chunk_header_size;
>     offset<uint<32>,B> chunk_size;
>
>     // Data:
>     uint<8>[chunk_size - data'offset] data;
>   };
>
> doesn't:  "error: undefined variable 'data'"
>
> How about documenting this trick where the 'offset attribute is described?

In the body of a struct or union you can use OFFSET, which is the
current offset from the beginning of the struct type.  Something like
this:

type ABXML_chunk =
  struct
  {
    // Chunk header:
    uint<16> chunk_type;
    offset<uint<16>,B> chunk_header_size;
    offset<uint<32>,B> chunk_size;

    // Data:
    uint<8>[chunk_size - OFFSET] data;
  };




reply via email to

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