Page 1 of 1

parameter passing

Posted: Tue Jun 17, 2014 7:59 pm
by PaPi
I believe that there is something wrong With fnxcompiler(21.12.2013):
I do not know, the parameter passing of subroutines or/and functions
how is it done? By value, or by address in fnxbasic?
For me it caused trouble several times, and unexplained phenomena encountered.
Here an test:
[code]

`param.bas by PaPi 17-06-2014
object mainform as form
  width=200
  left=200
  center
  onmousedown=omd
  showmodal
end object

sub omd(b as integer,sh as integer,u as integer,v as integer)
  dim x1 as single,y1 as single,z as integer
  x1=u
  y1=v
  z=99
  print "Bad:"
  wr(x1,y1,z)
  print "Good:"
  wr(x1,y1,88)
end sub

sub wr(x as single,y as single,k as integer)
  print x,y,k
end sub
[end code]

Help me, please, Marco!
PaPi

parameter passing

Posted: Wed Jun 18, 2014 11:59 am
by PaPi
My code has a sense of fault (replaced "bad" and "good"), please, consider replacing this new code:
[code]
`param.bas by PaPi 17-06-2014
object mainform as form
width=200
left=200
center
onmousedown=omd
showmodal
end object

sub omd(b as integer,sh as integer,u as integer,v as integer)
dim x1 as single,y1 as single,z as integer
x1=u
y1=v
z=99
print "Good:"
wr(x1,y1,z)
print
print "Bad:"
wr(x1,y1,88)
print
print "Bad too:"
wr u,v,111
end sub

sub wr(x as single,y as single,k as integer)
print x,y,k
end sub


[end code]

parameter passing

Posted: Thu Jun 19, 2014 3:09 pm
by Marco
Hi, The puzzling is about returning the parameters,

if you do this:

dim a as integer

sub test(x as integer)
x=10
end sub

test(a)

variable a now contains 10 because a is replaced by x in the sub.

This can be passed by using a function for it or by using a static variable

dim a as integer,b as integer
a=10
b=a

sub test(x as integer)
x=20
end sub

test(b)

a now contains still 10
b now contains 20

I hope this will clear some things, so sub passes the valueu of their parameters.

best regards marco







parameter passing

Posted: Thu Jun 19, 2014 5:29 pm
by PaPi
I mean, it`s okay. But that`s not the problem.
In my test program (param.bas) a subroutine (named sub omd) call another one (named sub wr),
and the values of the actual parameters does not appear
correctly (not always correctly) on the called subroutine.
See my program, and run it please!
Also, the question is: why print the wr subroutine bad results in some cases?
PaPi

parameter passing

Posted: Sat Jun 21, 2014 3:10 pm
by Marco
I see.... think it is some kind of bug, a work around is to make the wr sub a function.