BST Bug
Dave Hein
Posts: 6,347
I came across a BST bug that took me a while to track down. It appears that BST allows local stack variables to have the same name as a global variable. The code shown below compiles under BST, but the Prop Tool will display a compile error. It would actually be a nice feature if BST used the stack variable within the method, but it ignores the stack variable and uses the global variable instead.
CON _clkmode = xtal1 + pll16x _clkfreq = 80_000_000 OBJ ser : "FullDuplexSerial" DAT val long 1 PUB main ser.start(31, 30, 0, 115_200) waitcnt(clkfreq*3+cnt) test1(2) waitcnt(clkfreq/10+cnt) PUB test1(val) ser.dec(val)
Comments
Since OpenSpin is "the future" for spin code compiling in IDEs 'like' SimpleIDE, I don't think there's going to be any fix, especially since BST (with its compiler, "bstc") is no longer getting any support.
dgately
bst 0.19.5
compiler 0.15.4 pre5
-Phil
Totally disagree, local variables should never name clash, only shadow. Programming languages are just lambda-calculus after all.
Spin is not C. It has objects, there are no global variables, there are instance variables.
It always annoys me having to dream up new names for things to get around these issues. I might have a parameter "length", say. because that is the most obvious name for it, then I might want an instance variable "length" because that is also the most obvious name for it.
I was reminded of this recently when I had to make changes to a big old program in Pascal. In Free Pascal I need a different name for each of:
a) Parameters to methods.
b) Instance variables.
c) Names of any properties I define for the class.
d) Probably globals/module variables as well.
That Pascal code is full of "warts", fields in a class are prefixed with "F" and so on. Makes an ugly mess.
Like I said in the OP, it would be a "nice feature" if the global variable name could be used as a local variable within the scope of the method.