[comp.lang.c] Turbo Pascal to C conversion

JOER%TEMPLEVM.BITNET@wiscvm.wisc.EDU (07/07/87)

given the following code segment in Turbo Pascal ...

procedure pack(var page : pagetype ;
               key      : integer );
var
   i : integer;
   p : array[1..maxint] of byte ABSOLUTE page ;
begin
  ...
end;

how do I convert the ABSOLUTE reference to C ???
Joe Raube  Templevm@bitnet

toma@killer.UUCP (Tom Armistead) (07/10/87)

In article <8201@brl-adm.ARPA>, JOER%TEMPLEVM.BITNET@wiscvm.wisc.EDU (Joseph Raube) writes:
> procedure pack(var page : pagetype ;
>                key      : integer );
> var
>    i : integer;
>    p : array[1..maxint] of byte ABSOLUTE page ;
> begin
>   ...
> end;
> 
> how do I convert the ABSOLUTE reference to C ???
> Joe Raube  Templevm@bitnet

Use pointers... Something like this

void pack(page, key)
pagetype *page;
int      key;
{
    /* now any references to page will actually be accessing what */
    /* page points to (thus 'absolute') */
    pagetype *p;

    p = page;    /* now p 'points' to the same thing as 'page' */
                 /* and any changes to one will affect the other... */

}
/* and when you call pack, pass the 'page' parameter with an 'address of' */
/* operator in front of it, like this... */

main()
{
pagetype apage;
int      akey;

/* do your stuff with apage and akey */
    pack(&apage, akey);
/* now any refferences made to the apage variable in the pack routine will */
/* be made to the actual apage variable... */
}


UUCP:           ihnp4\
                      \killer!toma
  infoswx!convex!dj3b1/
Tom Armistead

archer@elysium.SGI.COM (Archer Sully) (07/11/87)

In article <8201@brl-adm.ARPA>, JOER%TEMPLEVM.BITNET@wiscvm.wisc.EDU (Joseph Raube) writes:
> given the following code segment in Turbo Pascal ...
> 
> procedure pack(var page : pagetype ;
>                key      : integer );
> var
>    i : integer;
>    p : array[1..maxint] of byte ABSOLUTE page ;
> begin
>   ...
> end;
> 
> how do I convert the ABSOLUTE reference to C ???
> Joe Raube  Templevm@bitnet


it should look something like this:

int
pack(page, key)
pagetype *page;
int key;
{
	int i;
	int *p = (int *) page;
}

Archer Sully
archer@sgi.com
{ucbvax,sun,pyramid}!sgi!archer