Author Topic: Unused variable warning, when variable is used as a parameter  (Read 3524 times)

0 Members and 1 Guest are viewing this topic.

Offline GTC

  • Newbie
  • Posts: 49
  • Programmer's motto: *This* time it will work.
    • View Profile
Unused variable warning, when variable is used as a parameter
« on: December 18, 2020, 08:14:33 am »
QB64 compiler (v1.4)  is warning me about an unused string variable which in fact is used.

Here's a summary of the situation:

DIM SHARED F$

Call Blah ("hello")

End

Sub Blah (F$)
Print F$
End sub


FellippeHeitor

  • Guest
Re: Unused variable warning, when variable is used as a parameter
« Reply #1 on: December 18, 2020, 08:17:45 am »
If you're passing it as a parameter, you don't need it to be shared. If you're sharing it, you don't need to pass it as a parameter.

QB64 is having a hard time understanding your duality of variable naming - and I'm afraid I'll have to side with it ☺️

Offline GTC

  • Newbie
  • Posts: 49
  • Programmer's motto: *This* time it will work.
    • View Profile
Re: Unused variable warning, when variable is used as a parameter
« Reply #2 on: December 18, 2020, 08:22:57 am »
- and I'm afraid I'll have to side with it ☺️

Aha, and you' be correct! :-)

Thank you.

FellippeHeitor

  • Guest
Re: Unused variable warning, when variable is used as a parameter
« Reply #3 on: December 18, 2020, 10:00:43 am »
This will shed some more light:
  [ You are not allowed to view this attachment ]  

The local parameter takes precedence over a shared variable. Behaviour confirmed in QB4.5 too.
« Last Edit: December 18, 2020, 10:02:10 am by FellippeHeitor »

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: Unused variable warning, when variable is used as a parameter
« Reply #4 on: December 18, 2020, 10:22:42 am »
If you look at the c-translated code we output in internal/temp/main.txt, you'll see that the two are completely different beasts.

DIM SHARED F$   ---   In the main module, this will translate down to STRING_F, or something similar.

Sub Blah (F$) --- And this will translate down to STRING_BLAH_F, or something similar, which is completely different, and localized to Blah only.



Conclusion:  You can't SHARE the same variable as you're passing as a parameter.

On the same note, you can't use STATIC inside a SUB for the same reason.

Code: [Select]
DIM SHARED Foo
Foo = 1
PRINT Foo
Example
PRINT Foo


SUB Example
    STATIC Foo
    Foo = 2
    PRINT Foo
END SUB

Passing via parameter, or use of STATIC, makes the variable unique to the sub and not the same as one you might be sharing elsewhere.

https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline luke

  • Administrator
  • Seasoned Forum Regular
  • Posts: 324
    • View Profile