<< Previous Message Main Index Next Message >>
<< Previous Message in Thread This Month Next Message in Thread >>
Date   : Mon, 04 Jul 2005 11:39:53 +0100
From   : Richard_Talbot-Watkins@...
Subject: Re: This program will self destruct

Greg Cook wrote:

> You may know that the actual parameters of PROCs and FNs are
> automatically made LOCAL but restored in reverse order, which is why
> the ! fields must not overlap.  But the ? operator really goes wrong.

Interesting, thanks.

You're right about the ? operator - I've lost work through not knowing this
in the past.  Take the following, perfectly legitimate looking program:

10 FOR N%=0 TO 2 STEP 2
20 P%=&900
30 [OPT N%
40 OPT FNequb(32)
50 ]
60 NEXT
70 END
80 :
90 DEF FNequb(?P%):P%=P%+1:=N%

When I tried running this just now, it overwrote the four bytes following
'OPT' on line 40 with zeroes, causing the same 'self-destruct' effect.  The
question is: why does this happen?  It seems odd that there's a bug in the
? operator, which appears not to happen at all with the ! operator.  It's
as if it thinks that ?P% is 4 bytes long instead of 1, though I can't
imagine why it trashes mid-program memory.  Even the $ operator, with its
variable length value, appears to work OK.

(Of course, the above bit of code wouldn't actually work like an EQUB even
if Basic wasn't broken... since ?P% is 'local' to FNequb, its value would
be restored to its original value when exiting the function - something I
hadn't considered when trying to use that code years ago.  Good job it
broke really!)

Rich


**********************************************************************
This email and any files transmitted with it are confidential and
intended solely for the use of the individual or entity to whom they
are addressed. If you have received this email in error please notify
postmaster@...

This footnote also confirms that this email message has been checked
for all known viruses.

**********************************************************************
Sony Computer Entertainment Europe
<< Previous Message Main Index Next Message >>
<< Previous Message in Thread This Month Next Message in Thread >>