home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #27 / NN_1992_27.iso / spool / comp / lang / pascal / 6864 < prev    next >
Encoding:
Internet Message Format  |  1992-11-24  |  1.7 KB

  1. Path: sparky!uunet!news.univie.ac.at!apap4.pap.univie.ac.at!roesel
  2. From: roesel@apap4.pap.univie.ac.at
  3. Newsgroups: comp.lang.pascal
  4. Subject: Re: Pointer problems...
  5. Message-ID: <1992Nov23.182354.58@apap4>
  6. Date: 23 Nov 92 18:23:54 GMT
  7. References: <1992Nov21.181025.18275@jupiter.sun.csd.unb.ca>
  8. Organization: Vienna University Computer Center
  9. Lines: 66
  10.  
  11. In article <1992Nov21.181025.18275@jupiter.sun.csd.unb.ca>, tcsmith@mta.ca (Tim Smith) writes:
  12. > {*****problem 1**********************}
  13. > var
  14. >   p1: ^byte;
  15. >   p2: ^byte;
  16. >   p3   : pointer;
  17. > begin
  18. >   getmem(p3,100);
  19. >   p1:=P3;
  20. >   p2:=addr(p1);
  21. >   writeln(p1^,' ',p2^,' ');
  22. >           ^^^-----^^^ Why won't these two values be equal?
  23. >   freemem(p3,100);
  24. > end.
  25.  
  26. p2 points at the location where the pointer p1 itself is stored. E.g. if
  27. p1 is stored in memory at location 3000h:0 and points to 4000h:1234h then
  28. the memory at 3000h:0 contains the bytes 34h 12h 00h 40h. Therefore p2^
  29. would be 34h, whereas p1^ is the byte at 4000h:1234h, which can be of any
  30. value.
  31.  
  32. > {*****problem 2**********************}
  33. > var
  34. >   P1 : ^Byte;
  35. >   P2 : ^Byte;
  36.  
  37. Turbo Pascal treats these declarations as different ones, therefore it
  38. will not allow the following assignment
  39.  
  40. > begin
  41. >   new(p1);
  42. >   p2:=p1;   { Why is this illegal }
  43. >   dispose(p1);
  44. > end.
  45.  
  46. To solve the problem you must write
  47.  
  48. type
  49.  pByte = ^Byte;
  50.  
  51. var
  52.    P1 : pByte;
  53.    P2 : pByte;
  54.  
  55. { or alternativ
  56.  var
  57.  P1, P2 : ^Byte }
  58.  
  59. begin
  60.    new(p1);
  61.    p2:=p1;   
  62.    dispose(p1);
  63. end.
  64.  
  65.  
  66. I hope this helps
  67.  
  68.         Martin
  69.  
  70. ------------------------------------------------------------------------------
  71. Martin Roesel, Institute of Solid State Physics, University of Vienna, Austria
  72. roesel@apap1.pap.univie.ac.at
  73.