Anuradha wrote:
- Leave alone the const, even if i equate the pointer to 'nil'
the problem occurs.{ofcourse i did remove the writeln statement that dereferences the pointer}.
- Why such coding at all :
The whole code is in a function 'getmemory' that 'getmem's the required number of bytes and stores the number of bytes in the previous 2 bytes. There is also a procedure 'freememory' that reads the previous 2 bytes and frees as many bytes as was allocated earlier by getmemory. what could be the problem ?
program typcast1; type Mytype=record i : integer; c:^char; end; var p:pointer; begin getmem(p,sizeof(mytype)+2); fillchar(p^,sizeof(mytype)+2,0); word(p^):=sizeof(mytype); p:=pchar(p)+2; mytype(p^).c:=nil; end.
Totally unneccessary. The system remembers the size allocated all by itself.
getmem(p, sizeneeded); operateon(p^); dispose(p); p := nil; (* safety measure *)
Pascal is a simple language. It doesn't have pointer arithmetic for very good reasons. Don't try to contort it into C.
(I believe. Certainly Pascalp operates this way, so does C, which supplies the underlying library for GPC. Frank can confirm or deny).