parameter passing

Here one can report bugs or hold discussions about bugs updates and work arounds.
Post Reply
PaPi
Posts: 114
Joined: Wed May 16, 2007 11:55 am

parameter passing

Post: # 1189Post PaPi
Tue Jun 17, 2014 7:59 pm

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

PaPi
Posts: 114
Joined: Wed May 16, 2007 11:55 am

parameter passing

Post: # 1190Post PaPi
Wed Jun 18, 2014 11:59 am

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]

Marco
Site Admin
Posts: 246
Joined: Sat Sep 15, 2018 8:41 pm

parameter passing

Post: # 1191Post Marco
Thu Jun 19, 2014 3:09 pm

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







PaPi
Posts: 114
Joined: Wed May 16, 2007 11:55 am

parameter passing

Post: # 1192Post PaPi
Thu Jun 19, 2014 5:29 pm

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

Marco
Site Admin
Posts: 246
Joined: Sat Sep 15, 2018 8:41 pm

parameter passing

Post: # 1193Post Marco
Sat Jun 21, 2014 3:10 pm

I see.... think it is some kind of bug, a work around is to make the wr sub a function.

Post Reply