Shop Learn
Cannot use sub arguments in loops while option implicit — Parallax Forums

Cannot use sub arguments in loops while option implicit

pik33pik33 Posts: 1,216
edited 2022-01-13 13:01 in BASIC (for Propeller)
sub stopmotors(fl,fr,t)

' Stop motor from high speed to 0 in time t*10ms

dl=fl/t
dr=fr/t
for i= 0 to t
  fl=fl-dl : fr=fr-dr
  if fr<0 then fr=0
  if fl<0 then fl=0
  waitms 10: wypin(l_motor_pwm,fl) : wypin(r_motor_pwm,fr)   
next i  
pinlo(r_motor_enable) : pinlo(r_motor_break) : pinlo(l_motor_enable) :pinlo(l_motor_break) 
end sub

This generates warnings:

C:/Programowanie/ultibo-robot/01 obrum/Propeller/robuv_obrum023.bas:149: warning: definition of fl hides a member variable
C:/Programowanie/ultibo-robot/01 obrum/Propeller/robuv_obrum023.bas:156: note: previous definition of fl is here
C:/Programowanie/ultibo-robot/01 obrum/Propeller/robuv_obrum023.bas:149: warning: definition of fr hides a member variable
C:/Programowanie/ultibo-robot/01 obrum/Propeller/robuv_obrum023.bas:156: note: previous definition of fr is here

as if the compiler treats the loop as something other than the sub and don't tries to redeclare fl and fr.
Line 149 is

sub stopmotors(fl,fr,t)

What can I do? Option explicit and dim all variables (..... :( ...... ) ? Or is there any other way to do this?


Edit: removed option implicit while the program is still small, dimed all vars, now the compiler doesn't complain, but still.. it should not redeclare inner loop variables when they are declared in the function (if I declared these as var at the start of the function, the compiler still tried to redeclare them inside the loop.)

Comments

  • ersmithersmith Posts: 5,186

    @pik33 : That warning is bogus, and I'll try to fix it. But the generated code is correct, that is, "fl" and "fr" really are treated as function parameters.

    Thanks for the bug report,

Sign In or Register to comment.