atable_entry = array of table_entry;
andatable_entry = array [0..n-1] of table_entry;
The first array is known as dynamic. Is it possible to omit the [0..3] part somehow? Or in Pascal i have to pre-declare the size of a constant static array, the compiler cannot calculate the size by the entries?
Then use a pointer to the table entry. ( entries: Ptable_entry; with ptable_entry = ^table_entry; )It is already that way.
and overindex it like in CI don't understand this. I did not overindex anything in C. In the C version, the number of items was calculated by
You should really use CInt (https://www.freepascal.org/docs-html/rtl/ctypes/cint.html): In FPC integer (https://wiki.freepascal.org/Integer) depends on the used compiler compatibility mode.
table = record size: integer; entries: ptable_entry; end;
and overindex it like in CI don't understand this. I did not overindex anything in C. In the C version, the number of items was calculated by
sizeof(t_table_entries) / sizeof(table_entry)
Is it possible to omit the [0..3] part somehow? Or in Pascal i have to pre-declare the size of a constant static array, the compiler cannot calculate the size by the entries?If initialize during execution:
a
Thaddy, are you sure?Yes, of course. You can simply match the memory layout both ways. On the C side, pointers are required, on the Pascal side not. That is the point.
OP stated in his first post, that he wants to pass those records to a c-lib
a PChar has not data for length other than a NULL character in the string at some point.
Ansistring is a managed string which means all data before the actual start of the first character is for use of that string.
A Pchar can wrap around a manage string because even managed strings insert a #0 at the end just to make sure but is not counted as part of the string. So casting around the managed string will behave like a Pchar with no regard of what info is before it.
At least that is my take on it.. been that way since I can remember with Delphi.
Isn't it the case that PChar and AnsiString are basically the same, with their length just before it (MyString[-4]), but with a ref count and some more stuff before that? And that the length of a dynamic array is also stored in the 4 bytes just before where the pointer points?
So, shouldn't it work to just declare that dynamic array on the right location and be done with it?
This:
table: array of entries;
should be exactly the same as:
typedef struct { int size; entry *entries; } table;
On second thought: it isn't. "entry" is a pointer.
Is there a BufferLength before the Length as well?