From 21dbc6da97bb9058b372c025067203fc7cc1ca69 Mon Sep 17 00:00:00 2001 From: Irmen de Jong Date: Sat, 21 Mar 2020 12:51:32 +0100 Subject: [PATCH] doc --- docs/source/programming.rst | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/docs/source/programming.rst b/docs/source/programming.rst index f5a1f2f5c..79885c15a 100644 --- a/docs/source/programming.rst +++ b/docs/source/programming.rst @@ -375,7 +375,16 @@ Initial values across multiple runs of the program When declaring values with an initial value, this value will be set into the variable each time the program reaches the declaration again. This can be in loops, multiple subroutine calls, -or even multiple invocations of the entire program. If you omit an initial value, it will +or even multiple invocations of the entire program. + +.. sidebar:: + Zeroing not for ZP + + If a variable gets allocated in zero-page, it will *not* be set to zero for you at + the start of the program. Instead, it will simply be whatever the last value in that zero page + location was. Code should not depend on the uninitialized starting value of such variables. + +If you omit an initial value, it will be set to zero *but only for the first run of the program*. A second run will utilize the last value where it left off (but your code will be a bit smaller because no initialization instructions are generated) @@ -387,15 +396,6 @@ If you do modify them in-place, you should take care yourself that they work as expected when the program is restarted. (This is an optimization choice to avoid having to store two copies of every string and array) -.. caution:: - variables that get allocated in zero-page will *not* have a zero starting value when you omit - the variable's initialization. They'll be whatever the last value in that zero page - location was. So it's best to don't depend on the uninitialized starting value! - -.. warning:: - this behavior may change in a future version so that subsequent runs always - use the same initial values - Loops -----