FAQ  •  Register  •  Login

Var declaration checking

<<

wilco2009

Posts: 28

Joined: Sat Nov 24, 2012 1:23 am

Post Tue Dec 18, 2012 11:34 pm

Var declaration checking

Please, Could be possible to add an command option to require declare all variables.
I think, not declared variables is the source of bugs more difficult to find.
The problem is worse when you consider that BASIC is case sensitive.
<<

boriel

Site Admin

Posts: 1463

Joined: Wed Nov 01, 2006 6:18 pm

Location: Santa Cruz de Tenerife, Spain

Post Fri Dec 21, 2012 8:08 am

Re: Var declaration checking

This is "pending" task; it will eventually be implemented. It's the flag Explicit (see -lang qb)
http://www.freebasic.net/wiki/wikka.php ... onexplicit

I will implement it both as
#pragma option explicit

and as a command line flag: --option explicit

What do you think?
<<

wilco2009

Posts: 28

Joined: Sat Nov 24, 2012 1:23 am

Post Fri Dec 21, 2012 6:14 pm

Re: Var declaration checking

Perfect!
I think the sintaxis is very clear.
When you have the option implemented, I'll start using it.
As Pascal enthusiast, I think it should be active by default.
<<

boriel

Site Admin

Posts: 1463

Joined: Wed Nov 01, 2006 6:18 pm

Location: Santa Cruz de Tenerife, Spain

Post Sat Dec 22, 2012 10:41 am

Re: Var declaration checking

wilco2009 wrote:Perfect!
I think the sintaxis is very clear.
When you have the option implemented, I'll start using it.
As Pascal enthusiast, I think it should be active by default.

So do I. ZX BASIC started as a project with high Sinclair BASIC compatibility, but with the time I started to diverge in order to achieve higher performance. For compatibility, people should always use the --sinclair flag.
<<

boriel

Site Admin

Posts: 1463

Joined: Wed Nov 01, 2006 6:18 pm

Location: Santa Cruz de Tenerife, Spain

Post Sat Dec 22, 2012 7:40 pm

Re: Var declaration checking

Okay, I think I've implemented this one. Download 1.3.0s959.
Use:
  Code:
zxb --explicit <yourprogram.bas>
To compile it.
The following program:
  Code:
LET a = 5

Should trigger an error if you compile it with --explicit option.
You can also use #pragmas in source code, which is a way to change compiling options from within the source code.
  Code:
REM The following line will override command line parameters
#pragma explicit = True
LET a = 5

NOTE: The OPTION command won't be implemented (it's being deprecated even in FreeBASIC). #pragmas are used in C/C++ compilers, and FreeBASIC. So ZXBASIC will support them too.
<<

wilco2009

Posts: 28

Joined: Sat Nov 24, 2012 1:23 am

Post Sat Dec 22, 2012 10:28 pm

Re: Var declaration checking

It's great!

Many thanks. Both options are checked and are working perfectly.

Return to Wishlist

Who is online

Users browsing this forum: No registered users and 3 guests

cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by Vjacheslav Trushkin for Free Forums/DivisionCore.

phpBB SEO