Unused variables,constants, functions subs warnings.
-
- Posts: 193
- Joined: 25 January 2006, 19:56 PM
Unused variables,constants, functions subs warnings.
As programs get larger in size, is there a way that the programmer can be warned of unused variables, constants, functions and subs?
partial answer...
I read in the docs that there's a compiler command line option to omit subs and fuctions that aren't called.
I wondered if this would be a way to have a "library" at the source code level, of favorite goodies. Put them all into some standard source files. Include all those with any project and be assured that only the ones really used would be compiled.
I read in the docs that there's a compiler command line option to omit subs and fuctions that aren't called.
I wondered if this would be a way to have a "library" at the source code level, of favorite goodies. Put them all into some standard source files. Include all those with any project and be assured that only the ones really used would be compiled.
The compiler will normally (with the default optimization options) omit unused subs/functions/variables. It may even optimize away variables that are used but aren't really necessary. Consider this trivial example:
With the default optimization levels, the generated code is:
You can see that no local variable space was allocated at the beginning of Main() and constant values are pushed in place of the variable values. Those variables are unnecessary in this case since the compiler can determine what the value of those variables will be at the point of use at run-time and they aren't otherwise used.
Code: Select all
Sub Main()
Dim pin as Byte
Dim level as Byte
pin = 12
level = 2
Call PutPin(pin, level)
End Sub
Code: Select all
Sub Main()
Dim pin as Byte
var:pin (1) [not used]
Dim level as Byte
var:level (1) [not used]
pin = 12
level = 2
Call PutPin(pin, level)
0011 1a0c PSHI_B 0x0c (12)
0013 1a02 PSHI_B 0x02 (2)
0015 d4 PUTPIN
End Sub
0016 06 RET
- Don Kinzer
Re: Unused variables,constants, functions subs warnings.
The answer to the question is to look at the listing file and also generate the called-by and called-from lists. The compiler options to add to the PJT file are:zbasicandy wrote:As programs get larger in size, is there a way that the programmer can be warned of unused variables, constants, functions and subs?
Code: Select all
--list=<filename>
--called-by-list
--calls-list
Code: Select all
--warn=unused-param
Mike Perks
This is a result of the lessons learnt when Don and I did some similar work for the predecessor to ZBasic called BasicX - see the bxDism utility on my website. So this is second generation technology at least (produced by a different company).stevech wrote:Impressive!
This sounds like a good idea to add to the documentation.stevech wrote:Is there a way to see what the default compiler options are?
Mike Perks
The help text output for optimization and warning options indicates which options are in effect by default.Is there a way to see what the default compiler options are?
Code: Select all
zbasic --help-optimize
zbasic --help-warning
- the executable output file has the same name as the project file (or the first file compiled) with the extension replaced by .zxb
- the map file has the same name as the project file (or the first file compiled) with the extension replaced by .map
- Don Kinzer