Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!samsung!zaphod.mps.ohio-state.edu!sdd.hp.com!ucsd!ucbvax!LSUVM.BITNET!$CSF214 From: $CSF214@LSUVM.BITNET (John Mills) Newsgroups: comp.sys.apple2 Subject: Re: new() procedure in Pascal Message-ID: <9009141703.AA15123@apple.com> Date: 14 Sep 90 15:37:47 GMT References: Sender: daemon@ucbvax.BERKELEY.EDU Organization: The Internet Lines: 38 Joel Sumner writes: >One more Pascal related question. When should I call the following? > >var p:pointer (or StringPtr, or anything pointer) >begin >.... >new(p); >.... >end; > >In other words, when do you have to call new()? Only when it is defined >in 'var' headings? Only global 'var' headings? How about as value parameters >of a procedure/function? I was writing a program that kept crashing >(corrputed string) until I called new(mystringptr). But I have made >other programs before that do similar things and I never used new(). I >am confused. Someone please help me. > >Thanks Joel, you have defined the variable "p" to be of type "pointer" in this example. A pointer can be thought of as a variable holding an integer number, which is in itself the address, in memory, of some data structure (be it integer, record, whatever). When you test-run the program, NEVER assume that your variables have some pre-initialized value; i.e. all variables are assumed to be UNDEFINED in value. This is what the "new(p)" procedure is for. Specifically, the "new" procedure allocates storage space in memory for the "pointed-to" data structure and then puts the address of the storage space in the variable "p". In short, to answer your question "when do you have to call new()," I would say use it whenever you need to create new storage space for your data structure. ======================================== Bitnet : $csf214@lsuvm Internet : $csf214@lsuvm.sncc.lsu.edu ========================================