[futurebasic] Re: [FB] PG error ?

Message: < previous - next > : Reply : Subscribe : Cleanse
Home   : April 1999 : Group Archive : Group : All Groups

From: Derek Smith <dereksmi@...>
Date: Thu, 8 Apr 1999 15:21:49 -1000
On Thu, 8 Apr 1999, Sylvain Guillemette wrote:

> >(1) There is a mistake in your function name. FN buildGWorld(@rectPtr&)
> >should be FN buildGWorld&(@rectPtr&), so that it can return a LONG value
> >(END FN = theWorld&).
> 
> The function in PG has no '&' in the function name.


FB function return types default to long, so this isn't required.  

Since I know somebody will ask why this doesn't cause a memory overwrite I
will give some more info:

LOCAL FN Foo
 ...
END = myVar&

x% = FN Foo

Will not cause a memory overwrite on the variable x% and its neihbors
because the MyVar& result is stored in a register and FB knows to grab
only two bytes from this register.  This means that the stack isn't left
messed up as well.  If it grabbed only the first two bytes off the stack
then we'd have a real problem.  Since FB functions return values thru a
register it is safe to call Fn Foo without assigning its result to
anything.

x = 10
FN Foo
STOP

However, a toolbox call WILL use the stack to return the result which will
seriously screw up the stack if you ignore the result.


-Derek Smith
-------------------------------------------------------------------------------
                "Getting my coworkers fired with FutureBasic"
                            FB 1, Coworkers 0
Homepage of FutureBasic resources and other pointless stuff at
http://www2.hawaii.edu/~dereksmi
------------------------------------------------------------------------------