[fpc-pascal]memw

Marco van de Voort marcov at stack.nl
Sun Feb 23 19:28:36 CET 2003


[ Charset ISO-8859-1 unsupported, converting... ]
> Hi, James!
> 
> On Sunday 23 February 2003 18:44, you wrote:
> 
> > This is from an old Turbo Pascal source of the Pascal S compiler source:
> >
> >           getmem(spnt,((sleng+3) div 16 +1)*16);
> >           k := seg(spnt^);
> >           memw[k:0] := sleng;
> >           memw[k:2] := 0;
> >           move(sbuff[1],mem[k:4],sleng);
> >
> > How would you convert that into FPC syntax for linux ?
> 
> just a first approach by heart - i neither tested it, nor did i check the 
> syntax. if you need explanation or testing, i can do that. but maybe it works 
> at once:
 
> type
>   p_words = ^ t_words;
>   t_words = array [0 .. maxint] of word;
> 
> var
>   spnt: p_words;
> 
> begin
>   getmem(spnt,((sleng+3) div 16 +1)*16);
> ? spnt ^ [0] := sleng;
> ? spnt ^ [1] := 0;
> ? move(sbuff[1], @(spnt ^ [2]),sleng);
> end.


This is correct. I think, but probably the size passed to getmem is also
special. All the calculation is only to make sure that memory is allocated in
pieces of 16 bytes. (a segment), but that doesn't matter much anymore.

So that probably can change to simple 

getmem (spnt,sleng+3);
if that is the size needed.

Better, the entire stuff could simply change to use a pointer to an array of
record (with two fields in it). It might be a workaround to TP's 64k limit
that FPC doesn't have. (or do you heapalloc for that?)

Also be careful with this kind of code if it stores pointers, because
pointers are 32-bit now!




More information about the fpc-pascal mailing list