[futurebasic] Re: [FB] Projects and Includes

Message: < previous - next > : Reply : Subscribe : Cleanse
Home   : September 2009 : Group Archive : Group : All Groups

From: Brian Stevens <bstevens33@...>
Date: Wed, 23 Sep 2009 07:07:07 -0700
On Sep 22, 2009, at 10:37 PM, Robert Purves wrote:

> Bill Zielenbach wrote:
>
>> Perhaps I misunderstood how parameters worked in a function call. I  
>> have had
>> the impression that variables/arrays included in a function call  
>> could be
>> accessed ("read") by the function, but not successfully modified  
>> within the
>> function ("written"). This was a distinct difference from my Fortran
>> experience where the addresses were passed and any actions within the
>> subroutine affected the variables/arrays passed to it.
>>
>> It was this perhaps misunderstanding that caused me to use globals  
>> for any
>> routines that needed to change multiple variables/arrays beyond the  
>> single
>> variable that could be passed back as result=fn whatever(variable1,  
>> array2,
>> etc).
>
> Array parameters behave as in C and Fortran: they are pass-by- 
> address; changed array element values are seen by the caller.

The array can also be a local to a function and passed to another  
function and doesn't have to be global. Here is a slightly modified  
version of Robert's example:

local fn Test( x(100) as long )
'~'1
x(7) = 1
end fn

local fn Driver
'~'1
dim as long gArray(100)

print "Before:", gArray(7)
fn Test( gArray(0) )
print "After:", gArray(7)

end fn

fn Driver

do
HandleEvents
until gFBQuit



Brian S