Anuradha wrote:
I am really sorry for having missed a ^ in the program but you see, the program really worked in BP and not in GPC.But i do know that it is stupid to manipulate some parts of the pointer.kindly delete the previous mail. It is this program that i have problems in.
program typcast1; const ct :char='h'; 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:=@ct; writeln(mytype(p^).c^); end.
What are you trying to do? Why are you distorting the language? A const is a const, not a type (silly borland extension). EP and GPC have the value attribute if you have to initialize something, but it is better to write explicit code and not depend on extensions.
If you stick to the real language your code will be much clearer, and has a good chance of working.
From the little I see you would be advised to declare:
const ctv = 'h'; type Mytype = record i : integer; c : ^char; end;
recdptr = ^therecd; therecd = RECORD size : integer; content : mytype; end;
var p : recdptr;
ct : char;
.... ct = ctv; new(p); WITH p^, therecd DO BEGIN (* init ALL the fields *) size = sizeof(mytype); new(c); c^ = ctv; i = whatever; END;
Which should work both under real Pascal and under TPC/BP.