Code size

Discussion about the ZBasic language including the System Library. If you're not sure where to post your message, do it here. However, do not make test posts here; that's the purpose of the Sandbox.
Post Reply
FFMan
Posts: 502
Joined: 09 January 2010, 12:52 PM

Code size

Post by FFMan »

If i have a module that contains several functions/subs, is it safe to assume only the code that is called is compiled into the final downloaded.

i.e. if i put all functions relating to an esp8266 in a module, but don't call some of them from a particular MAIN program, does unused code occupy any space ?
dkinzer
Site Admin
Posts: 3120
Joined: 03 September 2005, 13:53 PM
Location: Portland, OR

Re: Code size

Post by dkinzer »

FFMan wrote:If i have a module that contains several functions/subs, is it safe to assume only the code that is called is compiled into the final downloaded.
Yes. This type of optimization is implemented on two levels for native mode devices. Firstly, when the ZBasic compiler is producing C or C++ code, it only generates code for the procedures that are referenced (unless the ZBasic optimization directs otherwise). Secondly, when the back end compiler processes the generated code it also optimizes to remove unused code.

Of course, determination of whether a procedure is unused is done using static analysis, i.e. if there is a invocation reference to a procedure that might be followed it is considered "used" even it the procedure is never actually invoked at run time.

You can test this by noting the code size, adding an unused subroutine and then noting the resulting code size.
- Don Kinzer
Post Reply