Sorry for the wrong sample program and a silly doubt.The problem is we have large codes already written and we work in the support department that converts these sources to executables runnable on unix and i cannot change much of the code. This time i have analysed more and am attaching a code that works fine in BP and doesnot work in GPC.It is something to do with the pointers. Can you kindly tell me what the problem is?
You do things with pointers that aren't allowed afiak.
program typcast1; {type word=word(16);} type Mytype=record c:char; end; var p:pointer; begin getmem(p,sizeof(mytype)+2);
Allocates a number of bytes,ok. (not necessarily 3 though, since the record may be padded)
word(p):=sizeof(mytype);
Here you cast a 32-bit pointer to a 16-bit Word, to set the lower word to one or two, which practically makes it a dangling pointer.
It seems that you try to exploit both the 16-bits seg:offset dos memory model, AND the fact that TP's default memory manager aligns on segment borders (which it afaik only does when in protected mode, in real mode it afaik aligns on 8 bytes)
It is something that might even fail if you use some unit that takes over the heapmanager in a TP program, let alone different 32-bit compilers that run on different operating systems.
p:=pchar(p)+2;
Should be possible. Doesn't deserve a beauty price though.
mytype(p^).c:='h'; writeln(mytype(p^).c); end.