Spin 2 - cannot use a local variable/function parameter name in dat section - bug or feature?
pik33
Posts: 2,366
I am trying to convert a video driver from p1 to p2 using a Propeller Tool 2.4.1.
There is a method: pub setfontcolor(line,pos,r,g,b) | temp, place, color
It returns an error: "Expected a unique parameter name"
It seems it is because of "line" being a label in in the dat section in the same file: a pasm code to run in another cog via coginit.
After I renamed a PASM label to 'line2' it compiled OK
This means I cannot use a spin method's local - local! variable names in dat section... I have to remember them all - why? They are local, these names should be not visible outside a method.
Or is there any trick I don't know as a P2 beginner?
Comments
It's not that the local variables are visible outside the method, but that DAT variables are visible within the method, right? DAT variables need to be visible everywhere in the file, unlike local method variables. Maybe I'm not understanding, or you just disagree with how it works.
So I simply have to remember about this and avoid using the same names in spin method and dat sections.
The first time I encountered this error, there was a confusion: what the compiler wants? In "bigger" languages local declared variables simply hide the global ones if there is a conflict and this was the source of the confusion.
Presuming I understand this correctly...
Within an object
Hope I have this correct
And then the names in DAT sections have absolute priority and cannot be reused anywhere else, or the compiler will generate an error. So if there is "line" label in DAT, you cannot have pub xyz() | line. One of these names has to be changed ot the program will not compile
As I can remember, there was a topic somewhere with P2 tips and traps, maybe we need to make this get pinned on top of the P2 forum to make first steps with P2 easier.
Another trap: don't mix defined longs with res. It will compile, but a long defined after res will become another undefined res.