[futurebasic] Re: [FB] Projects and Includes

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

From: Robert Purves <listrp@...>
Date: Wed, 23 Sep 2009 17:37:49 +1200
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.

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

begin globals
dim as long gArray(100)
end globals

print "Before:", gArray(7)
fn Test( gArray(0) )
print "After:", gArray(7)
do
HandleEvents
until gFBQuit


Robert P.