#ADDRESS etc, question
3 messages in this thread
Leon,
I have a question about BM2 compiler. I looked in the manual but couldn't find
a clear answer. Is this code legal Modula-2?
VAR p1, p2 : ADDRESS;
p1 := ADDRESS(p2^);
Since ADDRESS is defined to be a POINTER to BYTE, this code doesn't do what I
expected. It takes a BYTE pointed to by "p2" and extends it to a LONGWORD, nd
the places result in "p1". A spectacular crashes follow soon after.
This type transfer should be illegal since the variables are not of the same
size (i.e. one is BYTE and the other is ADDRESS). This is according to Wirth.
BTW, this code occured in a module that I was porting from a VAX, where ADDRESS
is defined as POINTER TO LONGWORD.
Comments? …. Richie
Richie:
The sample of code in your message is perfectly legal. Type coersion has
virtually no limitations placed on it in Modula-2. In most cases all that
happens is that either high-bits are truncated or zero-extended depending on if
you are going smaller to larger or vice-versa. One possible reason for the
problem in porting from the VAX is that BM-2 defines ADDRESS as POINTER TO
BYTE, where as your VAX compiler probably defines it as POINTER TO WORD (with
WORD being 32-bits, probably). So on the VAX this picks up a 32-bit pointer
value on the Amiga it only gets the first 8-bits of the pointer, which is
probably why the system crashed later as you mentioned.
>> Leon Frenkel <<
Actually, in Modula-2 type transfer should only happen between variables of the
same size. Certain compiler provided extensions (like our VAX compiler) that
allow type transfer between variables which are less than four bytes in size.
But that's a documented extension.
Benchmark seems to do something similar, but I couldn't find the documentation.
Anyway, this is not that important. If you play with addresses too much, you
deserve all the trouble you get yourself into.
Richie