This is it.
..
or not?
yes using {$RANGECHECKS OFF} is the right way
...all of this wouldn't be needed if an empty array could be applied at the end..
the feature is not even a part of the official C-standard.
why would it be needed for the implementation in pascal?
One could do an implementation like this:
desc = record
length : Cardinal;
count : Cardinal;
end;
desc_list = record
num_desc : Cardinal;
descs : array [0..0] of desc; // remember to disable Range check when using desc_list
end;
tdescarray = array [word] of desc; // even "Integer" would work for 64-bit mode
pdescarray = ^tdescarray;
desc_listPtr = record
num_desc : Cardinal;
descs : pdescarray;
end;
procedure InitDescList(const inp: desc_list; out pt: desc_listPtr )
begin
pt.numdesc := inp.numdesc;
pt.descs := @inp.descs;
end;
and dealing with "pt.desc" would allow to avoid RANGECHECKS off (assuming num_desc is less than 65535... which usually it's less than that)
Another approach is similar to suggested originally:
desc_list = record
num_desc : Cardinal;
descs : array [word] of desc; // array[byte]?
end;
The actually approach on how to deal with the C-specific type should be chosen based on several things:
* is the type only returned from the library (and doesn't need be built by the program)
* what the maximum num_desc is "logically" expected/possible. (could a type declared with a certain amount of entries in the array)
* is the data returned from desc_list will be copied over to some other storage within the program. (if yes, then dealing with RANGECHECKS off one time, will solve the problem)