[comp.sys.apple2] ORCA/Pascal dynamic arrays

chin@ankh.ftl.fl.us (Albert Chin) (07/04/90)

Is it possible to do the following in Pascal, like in C:

char *pointer;

..

pointer=malloc(4000*sizeof(char)); /* dynamically allocate pointer[4000] */

-------

thanks,

albert ... mthvax!mamia!albert

dlyons@Apple.COM (David A. Lyons) (07/05/90)

In article <368@ankh.ftl.fl.us> chin@ankh.ftl.fl.us (Albert Chin) writes:
>Is it possible to do the following in Pascal, like in C:
>
>char *pointer;
>..
>pointer=malloc(4000*sizeof(char)); /* dynamically allocate pointer[4000] */

Sure:
 ----------
type MyArrayType = array[1..4000] of char;

var  MyArrayPtr: ^MyArrayType;
...
    new(MyArrayPtr);
    MyArrayPtr^[100] := 'x';
 ----------

Or, if you prefer:

 ----------
type MyArrayType = array[1..4000] of char;
     MyPtrType   = ^MyArrayType;

var  MyArrayPtr:  MyPtrType;
...
   MyArrayPtr := MyPtrType(NewHandle(4000,_ownerid,attrLocked+attrFixed,nil)^);
   { note the type-cast to "MyPtrType" and the "^" to dereference the handle }
 ----------
-- 
David A. Lyons, Apple Computer, Inc.      |   DAL Systems
Apple II Developer Technical Support      |   P.O. Box 875
America Online: Dave Lyons                |   Cupertino, CA 95015-0875
GEnie: D.LYONS2 or DAVE.LYONS         CompuServe: 72177,3233
Internet/BITNET:  dlyons@apple.com    UUCP:  ...!ames!apple!dlyons
   
My opinions are my own, not Apple's.

reeder@reed.bitnet (Doug Reeder,,,2343817) (07/12/90)

In article <368@ankh.ftl.fl.us> chin@ankh.ftl.fl.us (Albert Chin) writes:
>Is it possible to do the following in Pascal, like in C:
>char *pointer;
>..
>pointer=malloc(4000*sizeof(char)); /* dynamically allocate pointer[4000] */

   Pascal considers pointer arithmetic to be a source of program anarchy, so
it is not allowed.  There are no Pascal statements that correspond to
EXACTLY to the above C code.  If you want a data structure of fixed size, an
array will do nicely.  If the data structure size is determined after
compile-time, you must build a linked list, unless you're using an ISO 
level 1 compliant compiler with conformant arrays.

Doug Reeder                                   USENET: ...!tektronix!reed!reeder
from ARPA: tektronix!reed!reeder@berkeley.EDU BITNET: reeder@reed.BITNET
7th: Each swallow works hard to be perfect pilot-provider-builder-trainer-
teacher-lover-mate,no half-true hate!   - Dr.Brommer's 18-in-1 Pure Castile Soap