Posts: 22
Threads: 6
Joined: Feb 2021
Reputation:
2
Hi everyone,
I'd like to use --explicit to force me to define all variables before using them, to reduce the risk of bugs. However, I see an issue because my program uses the Print42 library and it contains a definition that seems to violate the --explicit option.
Specifically, if you try to compile a program that includes Print42 library, using --explicit, you will see an error something like:
Code: C:/opt/zxbasic-1.14.0/zxbasic/src/arch/zx48k/library/print42.bas:16: error: Undeclared variable "printAt42Coords"
C:/opt/zxbasic-1.14.0/zxbasic/src/arch/zx48k/library/print42.bas:17: error: Undeclared variable "printAt42Coords"
I considered updating the library source, so that printAt42Coords is defined. However, printAt42Coords is a code label, not a normal variable. The compiler complains because the label is dereferenced with an @printAt42Coords operation to work out the address at which to store the current coordinates:
Code: SUB printat42 (y as uByte, x as uByte)
POKE @printAt42Coords,x
POKE @printAt42Coords+1,y
END SUB
...
printAt42Coords:
...
I don't know what type of variable printAt42Coords is, so can't add a 'dim' statement to define it. I tried defining it as a 'uinteger', but then the compiler complains when it tries to use as a label "error: identifier 'printAt42Coords' is a var, not a function"
Anyone know how to work around this?
Thanks in advance,
Posts: 1,763
Threads: 55
Joined: Aug 2019
Reputation:
24
(03-13-2021, 10:59 AM)georgeo Wrote: Hi everyone,
I'd like to use --explicit to force me to define all variables before using them, to reduce the risk of bugs. However, I see an issue because my program uses the Print42 library and it contains a definition that seems to violate the --explicit option.
Specifically, if you try to compile a program that includes Print42 library, using --explicit, you will see an error something like:
Code: C:/opt/zxbasic-1.14.0/zxbasic/src/arch/zx48k/library/print42.bas:16: error: Undeclared variable "printAt42Coords"
C:/opt/zxbasic-1.14.0/zxbasic/src/arch/zx48k/library/print42.bas:17: error: Undeclared variable "printAt42Coords"
I considered updating the library source, so that printAt42Coords is defined. However, printAt42Coords is a code label, not a normal variable. The compiler complains because the label is dereferenced with an @printAt42Coords operation to work out the address at which to store the current coordinates:
Code: SUB printat42 (y as uByte, x as uByte)
POKE @printAt42Coords,x
POKE @printAt42Coords+1,y
END SUB
...
printAt42Coords:
...
I don't know what type of variable printAt42Coords is, so can't add a 'dim' statement to define it. I tried defining it as a 'uinteger', but then the compiler complains when it tries to use as a label "error: identifier 'printAt42Coords' is a var, not a function"
Anyone know how to work around this?
Thanks in advance,
This might be a bug, because --explicit was never considered with labels.
I'll check it.
Posts: 1,763
Threads: 55
Joined: Aug 2019
Reputation:
24
(03-14-2021, 05:12 PM)boriel Wrote: (03-13-2021, 10:59 AM)georgeo Wrote: Hi everyone,
I'd like to use --explicit to force me to define all variables before using them, to reduce the risk of bugs. However, I see an issue because my program uses the Print42 library and it contains a definition that seems to violate the --explicit option.
Specifically, if you try to compile a program that includes Print42 library, using --explicit, you will see an error something like:
Code: C:/opt/zxbasic-1.14.0/zxbasic/src/arch/zx48k/library/print42.bas:16: error: Undeclared variable "printAt42Coords"
C:/opt/zxbasic-1.14.0/zxbasic/src/arch/zx48k/library/print42.bas:17: error: Undeclared variable "printAt42Coords"
I considered updating the library source, so that printAt42Coords is defined. However, printAt42Coords is a code label, not a normal variable. The compiler complains because the label is dereferenced with an @printAt42Coords operation to work out the address at which to store the current coordinates:
Code: SUB printat42 (y as uByte, x as uByte)
POKE @printAt42Coords,x
POKE @printAt42Coords+1,y
END SUB
...
printAt42Coords:
...
I don't know what type of variable printAt42Coords is, so can't add a 'dim' statement to define it. I tried defining it as a 'uinteger', but then the compiler complains when it tries to use as a label "error: identifier 'printAt42Coords' is a var, not a function"
Anyone know how to work around this?
Thanks in advance,
This might be a bug, because --explicit was never considered with labels.
I'll check it.
Ok, I think I've fixed it.
Please, download this new beta version and tell me if it works (with --explicit):
http://www.boriel.com/files/zxb/zxbasic-...a13.tar.gz
http://www.boriel.com/files/zxb/zxbasic-...beta13.zip
http://www.boriel.com/files/zxb/zxbasic-...-win32.zip
http://www.boriel.com/files/zxb/zxbasic-...x64.tar.gz
http://www.boriel.com/files/zxb/zxbasic-...cos.tar.gz
Thx
Posts: 22
Threads: 6
Joined: Feb 2021
Reputation:
2
Hi Boriel,
Thanks. I'll give it a try tomorrow, and report back.
Speak to you soon,
Georgeo.
Posts: 22
Threads: 6
Joined: Feb 2021
Reputation:
2
Hi Boriel,
Based on a quick test, the fix looks to work. I no longer see errors when I reference labels from within my code, plus the print42 library doesn't cause an error.
Thanks again. Looks good,
Georgeo.
Posts: 1,763
Threads: 55
Joined: Aug 2019
Reputation:
24
(03-25-2021, 06:02 PM)georgeo Wrote: Hi Boriel,
Based on a quick test, the fix looks to work. I no longer see errors when I reference labels from within my code, plus the print42 library doesn't cause an error.
Thanks again. Looks good,
Georgeo.
Good to know!
|