home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!news.univie.ac.at!apap4.pap.univie.ac.at!roesel
- From: roesel@apap4.pap.univie.ac.at
- Newsgroups: comp.lang.pascal
- Subject: Re: Pointer problems...
- Message-ID: <1992Nov23.182354.58@apap4>
- Date: 23 Nov 92 18:23:54 GMT
- References: <1992Nov21.181025.18275@jupiter.sun.csd.unb.ca>
- Organization: Vienna University Computer Center
- Lines: 66
-
- In article <1992Nov21.181025.18275@jupiter.sun.csd.unb.ca>, tcsmith@mta.ca (Tim Smith) writes:
- > {*****problem 1**********************}
- > var
- > p1: ^byte;
- > p2: ^byte;
- > p3 : pointer;
- > begin
- > getmem(p3,100);
- > p1:=P3;
- > p2:=addr(p1);
- >
- > writeln(p1^,' ',p2^,' ');
- > ^^^-----^^^ Why won't these two values be equal?
- > freemem(p3,100);
- > end.
-
- p2 points at the location where the pointer p1 itself is stored. E.g. if
- p1 is stored in memory at location 3000h:0 and points to 4000h:1234h then
- the memory at 3000h:0 contains the bytes 34h 12h 00h 40h. Therefore p2^
- would be 34h, whereas p1^ is the byte at 4000h:1234h, which can be of any
- value.
-
- >
- > {*****problem 2**********************}
- > var
- > P1 : ^Byte;
- > P2 : ^Byte;
-
- Turbo Pascal treats these declarations as different ones, therefore it
- will not allow the following assignment
-
- > begin
- > new(p1);
- > p2:=p1; { Why is this illegal }
- >
- > dispose(p1);
- > end.
- >
-
- To solve the problem you must write
-
- type
- pByte = ^Byte;
-
- var
- P1 : pByte;
- P2 : pByte;
-
- { or alternativ
- var
- P1, P2 : ^Byte }
-
- begin
- new(p1);
- p2:=p1;
- dispose(p1);
- end.
-
-
- I hope this helps
-
- Martin
-
- ------------------------------------------------------------------------------
- Martin Roesel, Institute of Solid State Physics, University of Vienna, Austria
- roesel@apap1.pap.univie.ac.at
-