What is the purpose of these two lines : ? word(p):=sizeof(mytype);
In real mode TP it sets the offset of the segment:offset pair to 1.
Probably it originally was meant as a simple inc(p);
The problem it expects that the offset part of a newly allocated block is always zero, which is afaik not true. (real mode TP allocates per half segment).
p:=pchar(p)+2;
inc(p,2); or p:=@p[2];
The overall effect therefore is inc(p,3); or p:=pchar(p)[3];
Hello,
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. ------------------------
But if i change p:=pchar(p)+2; to p:=pchar(p)+4; then it works.Is it something to do with the word-boundaries?
Thanks and regards, Anuradha
Marco van de Voort wrote:
-- S.Anuradha Generic Data Tools, Alcatel Chennai. Alcanet : 2-757-7123
Anuradha wrote:
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:
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.