Wolf Behrenhoff <NoSpamPleaseButThisIsValid2@gmx.net> wrote:
> Corax wrote:
> > Morning
> > Looking for help with GPC.
> > Move( rc, Pointer( @flds + fldCnt^ * SizeOf( rc ) ), SizeOf( rc ) );
> > The last parameter gives 'error: reference expected, value given'
> Although I don't know GPC:
> Are you sure that your problem is the last parameter? Move needs a
> var-variable as second parameter. So it should be
> Move(rc, Pointer(...)^, sizeof(rc));
> Besides: does GPC allow addititon of integers and pointers?
Only if explicitly enabled.
> Are you
> allowed to add something to @flds? I would prefer a typecast:
> Pointer(Longint(@flds) + fldCnt^*sizeof(rc))^
I'd also prefer this, however using `PtrInt' (guaranteed the same
size as pointer) instead of `LongInt' (often larger).
> The best way to fiddle with addresses this way is to use the
> PTR function.
> so something like
> mysegment:= seg(flds)
> Move( rc
> , Ptr(mysegment,myoffset)^,
> SizeOf( rc ) );
I don't think that's the best way, because it's dependent on the
obsolete 8086 segment/offset architecture. Even if some modern
compilers emulate it, it's ugly to read and write.
What's easier (and independent of the addressing structure) is
type-casting via arrays (sure, type-casting is also ugly, but less
ugly than pointer arithmetic, and depending on how you get your
`flds', you might even be able to avoid casting):
foo = array [0 .. whatever] of type of rc;
bar = ^foo;
Move (rc, bar (@flds)^[fldCnt^], SizeOf (rc));
This way you also get rid of one ugly `SizeOf' call. And in fact you
can remove the other one and the `Move' statement as well by simply
bar (@flds)^[fldCnt^] := rc;
This will fail for types that are not assignable in Pascal (files
and structures containing files), but if rc is of such a type, you
may want to find out why this limitation is there ... ;-)
Frank Heckenbach, firstname.lastname@example.org, http://fjf.gnu.de/
GnuPG and PGP keys: http://fjf.gnu.de/plan (7977168E)
Pascal code, BP CRT bugfix: http://fjf.gnu.de/programs.html
Free GNU Pascal Compiler: http://www.gnu-pascal.de/