Thanks for the clarification, Frank.
Since the code "works with BP but not GPC", I presumed the hardware was X86 (IA32) ... I think Anuradha needs to clarify this, because as you say, misaligned access may not work with some other processors. BTW, the code also requires that a "word" is 16 bits - since the documentation implies that this is not true on all hardware, this is another potential problem with the code.
Joe.
-----Original Message----- From: Frank Heckenbach [SMTP:frank@g-n-u.de] Sent: Saturday, November 03, 2001 4:52 AM To: gpc@gnu.de Subject: Re: Re :Typecasting | record-field boundary
da Silva, Joe wrote:
So it seems this issue has arisen, because someone has decided to create 'getmemory' and 'freememory' routines, which simulate the functionality of 'new' and 'dispose' - strange!!! <g>
Not quite. In BP (which the code was originally written for AFAIUI), `New' does not support run-time variable sizes (there are no schema types or similar in BP). So every allocation of variable size has to be done via GetMem, and freed via FreeMem. Furthermore, BP does not keep track of the size allocated by itself, and FreeMem must be passed the correct size. So this stuff makes kind of sense for BP, but is quite unnecessary for GPC.
Nevertheless, I can't see any reason why the sample code presented should fail, unless there is also some issue with accessing of record fields and their address alignment, right?
Apart from the 2 vs. 4 bytes (i.e., SizeOf (Integer/Word/SizeType/...)) problem, there can be alignment problems. The Intel IA32 processors allow misaligned access, though with a speed penalty, other processors will simply crash.
With a "shift" of 2 bytes, you're sure to get alignment problems. With a shift of 4 bytes (as would be reasonable for GPC, see above), you might get problems with large types (LongInt, real types). Not sure what diffferent processors require, but I wouldn't be surprised if such code crashes on non-IA32 machines.
Frank
-- Frank Heckenbach, frank@g-n-u.de, http://fjf.gnu.de/ GPC To-Do list, latest features, fixed bugs: http://agnes.dida.physik.uni-essen.de/~gnu-pascal/todo.html
da Silva, Joe wrote:
Since the code "works with BP but not GPC", I presumed the hardware was X86 (IA32) ... I think Anuradha needs to clarify this, because as you say, misaligned access may not work with some other processors. BTW, the code also requires that a "word" is 16 bits - since the documentation implies that this is not true on all hardware,
In fact, for GPC this is true for *none* of the platforms -- `Integer' and `Word' are at least 32 bit (64 on some). Of course, you can redeclare `Word' (see the System unit), though this is not recommended.
this is another potential problem with the code.
I think I mentioned this in my last mail.
Frank