On May 23, 6:42 am, HubbleBubble <phil_simm...@[EMAIL PROTECTED]
> wrote:
> Hi All,
>
> 1.
> For my sins I sometimes convert C progs into pascal. Most of the time
> I manage OK but once in awhile I tangled up in knots. Here is one such
> instance. This is part of some memory management code to store images
> in ems blocks.
>
> Sometimes I'm envious of the apparent fluidity with which C treats
> memory but this is tempered by the fact its not always abundantly
> clear what it's up to. This is part of an emsAlloc function. In this
> snippet 'emsLinestart' was previously declared as a pointer (unsigned
> int *emsLinestart). Offset,page,size,lines and bytes are words.
> dosalloc returns a far pointer (that's normalised to you and me). So
> emslinestart appears to be a pointer to the block of memory just
> allocated by dosalloc but then it morphs into an array of words?
> pointers? which hold the page frames. Considering this is a dynamic
> structure allocated on call to the emsalloc how does this translate
> into pascal code?
>
> if((emslinestart=(unsigned int *)dosalloc(4*lines) == NULL)return 0;
>
> // Ok so above = quit value if not allocated else a pointer to mem
>
> for (i=0;i<lines;++i) {
>
> emsLinestart[i<<l] = offset; // huh? this is an array now ? are
> these pointers?
> emsLinestart[(i<<l)+1] = page;
> offset +=bytes; // clear enough from here on
> if((offset+bytes) > 0x4000 {
> ++page;
> offset := 0;
> }
>
emsLinestart is just a pointer to integer - and C allows you to offset
from that address. So, say a=i<<1, then the line above is the ADDRESS
of emsLinestart + a, an offset - this is perfectly legal in C, which
allows a lot of dangerous things.
How to do it in Pascal? Sorry, always been a little rusty in Pascal
when it came to pointers. I would've thought it would be trival...
What flavor of pascal are you using? I'd guess "Borland" because of
the newsgroup, but one shouldn't assume (Turbo/Borland). What version,
as well?
I'm still a UCSD fan...
Ben


|