[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: how to get the offset of the current struct
From: |
Bruno Haible |
Subject: |
Re: how to get the offset of the current struct |
Date: |
Mon, 12 Feb 2024 01:45:46 +0100 |
Jose E. Marchesi wrote:
> > 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;
> > };
> ...
> 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;
> };
There is a small difference:
before_bulk_of_data'offset evaluates to the offset from the beginning
of the file (assuming the file is mapped at 0#B)
OFFSET evaluates to the offset from the beginning of
the struct type.
So, what I would need is:
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 - (SELF'offset + OFFSET)] data;
};
but that does not compile: "error: undefined variable 'SELF'".
Apparently it would be useful to have SELF be defined also outside of methods.
Bruno