[comp.lang.pascal] Pointers in TP

ijohnson@gara.une.oz.au (Ian Johnson) (04/05/91)

 
 This question is, hopefully, very simple.  Referring to the 'hugemats' 
 program by Kent Porter (as cited by Timo Salmi in his frequently asked
 questions and answers information) if I define a var as 
   SingleCol : colArray;
 and then in the program have the statement
   SingleCol := A^[25].col^;
 this appears to isolate the 25th row (col) of the matrix A.  My question
 is, is this safe?  I'm not really experienced with pointers, and am 
 worried that it may appear to work, but that the memory associated with
 SingleCol may be over written.
 
 Thanks in advance.
 
 
 Ian Johnson:  email  ijohnson@gara.une.oz.au

mdella@polyslo.CalPoly.EDU (Marcos R. Della) (04/05/91)

In article <5841@gara.une.oz.au> ijohnson@gara.une.oz.au (Ian Johnson) writes:
> and then in the program have the statement
>   SingleCol := A^[25].col^;
> ...is, is this safe?  I'm not really experienced with pointers, and am 
> worried that it may appear to work, but that the memory associated with
> SingleCol may be over written.

The thing that you are doing in the above statment is taking the VALUE of the
memory location pointed to by A^[25].col^ and storing that into the storage
location of the SingleCol variable.  The problem you get with pointers
starting to do strange things (at least what I think your worried about)
is when you start assigning pointers to pointers to get a value...

ie.  
VAR   a,b : ^integer;

   a^ := 5;
   b := a;

the value of b^ is now going to be 5.  If I set (a^ := 8) then b^ will
magically change to the value of 8 insted of the previous 5.  The reason is
that the pointer to the memory locations are the same. So when you change the
5 in memory with the a^ you get the same effect with the b^.

If a and b are different pointers, then b^ := a^ is safe from the above
manipulation...

There are a bunch to things to worry about pointers... Just experiment. Don't
worry, you'll get lost, pull out your hair and wonder where all your numbers
went to and why Null values are appearing...
 
Its all part of the fun...



-- 
..!csustan ->!polyslo!mdella    | mdella@polyslo | Whatever I said doesn't
..!sdsu ---/   Marcos R. Della  | (805) 544-4825 | mean diddly as I forgot
..!csun --/    1663 Phillips Ln.                / it even before finishing
..!dmsd -/     San Luis Obispo, CA 93401       / typing it all out!!! :-)