f



MOVE

Morning

Looking for help with GPC.

Move( rc, Pointer( @flds + fldCnt^ * SizeOf(  rc ) ), SizeOf( rc ) );

The last parameter gives 'error: reference expected, value given'

Any hints?

thanks you
0
Corax
11/18/2003 4:09:33 PM
comp.lang.pascal.misc 1854 articles. 0 followers. eng (34) is leader. Post Follow

3 Replies
506 Views

Similar Articles

[PageSpeed] 53

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? Are you
allowed to add something to @flds? I would prefer a typecast:

Pointer(Longint(@flds) + fldCnt^*sizeof(rc))^

HTH,
  Wolf

0
Wolf
11/18/2003 6:49:58 PM

Move( rc
         , Pointer( @flds + fldCnt^ * SizeOf(  rc ) ),
         SizeOf( rc ) );

my guess
the second argument is a type cast of an address with an address multiplied by a number. Which sounds very illegal to me.
The typecast pointer(....) does ot denote necessarily an addres but pointer(........)^ does.
further
The best way to fiddle with addresses this way is to use the
PTR function.
so something like

mysegment:= seg(flds)
myoffset:=ofs(flds)+fldcnt^*sizeof(rc);
Move( rc
         , Ptr(mysegment,myoffset)^,
         SizeOf( rc ) );

But personally I dont like constructions like this. You can never tell how a compiler optimises code. e.g. if sizeof(rc) = uneven
word align data may disturb things. Better use the addr of the denoted thing itself.
note the added ^ in some cases


0
Femme
11/19/2003 12:26:35 AM
In <3FBA69D6.DA680C45@gmx.net>,
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)
> myoffset:=ofs(flds)+fldcnt^*sizeof(rc);
> 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):

type
  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
writing:

  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

-- 
Frank Heckenbach, frank@g-n-u.de, 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/
0
Frank
11/30/2003 4:36:05 AM
Reply: