Arrangement issue

Status
Not open for further replies.

Sandro

Well-known member
Hi all,
I'm writing, loading, checking, modifying, again and again on my Teensy 3.6 since months... ok nothing strange.
My code is a bit large now but, since it's working fine, I'm going on adding more and more features... Since yesterday, when I noticed this weird behave that kept me awake at night: how is it possible that changing my code from this:

Code:
...
...
...
void access (int abc)
{
do this, do that...
}

void modify (int xyz)
{
do other..
}

to this:
Code:
...
...
...
void modify (int xyz)
{
do other..
}

void access (int abc)
{
do this, do that...
}

than the whole program doesn't work anymore?
Did anyone ever experienced this problem? Is it a matter of some setting in the Arduino IDE (Programmer... Optimize..), either I am going crazy?:eek:
Thank you
 
I observed similar strange issues on T3.6 when my program grew very large and when I used more than 90% of the RAM available.
 
compiler or run-time?

Problems are only on run time.
With the current arrangement (a good working one) the compiler "Parallel programmer" with Optimizer "Fastest + pure-code" sends many warnings... don't know if they are significant:

Code:
C:\Users\dell\AppData\Local\Temp\arduino_modified_sketch_26265\TEENSY_Expander_Caricamento_file_Encoders_R1.7.ino: In function 'byte encoder_update(int)':

C:\Users\dell\AppData\Local\Temp\arduino_modified_sketch_26265\TEENSY_Expander_Caricamento_file_Encoders_R1.7.ino:565:1: warning: control reaches end of non-void function [-Wreturn-type]

 }

 ^

C:\Users\dell\AppData\Local\Temp\arduino_modified_sketch_26265\TEENSY_Expander_Caricamento_file_Encoders_R1.7.ino: In function 'void loop()':

C:\Users\dell\AppData\Local\Temp\arduino_modified_sketch_26265\TEENSY_Expander_Caricamento_file_Encoders_R1.7.ino:465:16: warning: array subscript is above array bounds [-Warray-bounds]

   pot_value[pot][1] = analogRead(pot);

                ^

In file included from C:\Program Files (x86)\Arduino\hardware\teensy\avr\cores\teensy3/WProgram.h:45:0,

                 from C:\Program Files (x86)\Arduino\hardware\teensy\avr\cores\teensy3/Arduino.h:3,

                 from C:\Users\dell\AppData\Local\Temp\arduino_build_754619\sketch\TEENSY_Expander_Caricamento_file_Encoders_R1.7.ino.cpp:1:

C:\Users\dell\AppData\Local\Temp\arduino_modified_sketch_26265\TEENSY_Expander_Caricamento_file_Encoders_R1.7.ino:466:44: warning: array subscript is above array bounds [-Warray-bounds]

   if (abs(pot_value[pot][1] - pot_value[pot][0]) > isteresi) {

                                            ^

C:\Program Files (x86)\Arduino\hardware\teensy\avr\cores\teensy3/wiring.h:121:19: note: in definition of macro 'abs'

   typeof(x) _x = (x); \

                   ^

C:\Users\dell\AppData\Local\Temp\arduino_modified_sketch_26265\TEENSY_Expander_Caricamento_file_Encoders_R1.7.ino:467:18: warning: array subscript is above array bounds [-Warray-bounds]

     pot_value[pot][0] = pot_value[pot][1];

                  ^

C:\Users\dell\AppData\Local\Temp\arduino_modified_sketch_26265\TEENSY_Expander_Caricamento_file_Encoders_R1.7.ino:465:16: warning: array subscript is above array bounds [-Warray-bounds]

   pot_value[pot][1] = analogRead(pot);

                ^

In file included from C:\Program Files (x86)\Arduino\hardware\teensy\avr\cores\teensy3/WProgram.h:45:0,

                 from C:\Program Files (x86)\Arduino\hardware\teensy\avr\cores\teensy3/Arduino.h:3,

                 from C:\Users\dell\AppData\Local\Temp\arduino_build_754619\sketch\TEENSY_Expander_Caricamento_file_Encoders_R1.7.ino.cpp:1:

C:\Users\dell\AppData\Local\Temp\arduino_modified_sketch_26265\TEENSY_Expander_Caricamento_file_Encoders_R1.7.ino:466:44: warning: array subscript is above array bounds [-Warray-bounds]

   if (abs(pot_value[pot][1] - pot_value[pot][0]) > isteresi) {

                                            ^

C:\Program Files (x86)\Arduino\hardware\teensy\avr\cores\teensy3/wiring.h:121:19: note: in definition of macro 'abs'

   typeof(x) _x = (x); \

                   ^

C:\Users\dell\AppData\Local\Temp\arduino_modified_sketch_26265\TEENSY_Expander_Caricamento_file_Encoders_R1.7.ino:467:18: warning: array subscript is above array bounds [-Warray-bounds]

     pot_value[pot][0] = pot_value[pot][1];

                  ^

Lo sketch usa 85252 byte (8%) dello spazio disponibile per i programmi. Il massimo è 1048576 byte.
Le variabili globali usano 97828 byte (37%) di memoria dinamica, lasciando altri 164316 byte liberi per le variabili locali. Il massimo è 262144 byte.

Thank you!
 
I observed similar strange issues on T3.6 when my program grew very large and when I used more than 90% of the RAM available.

After loading the compiler windows says (sorry for google translation from italian..):

Sketch uses 85252 bytes (8%) of the space available for programs. The maximum is 1048576 bytes.
Global variables use 97828 bytes (37%) of dynamic memory, leaving another 164316 bytes free for local variables. The maximum is 262144 bytes.

Maybe in the runtime RAM occupation grows?
Thank you
 
Problems are only on run time.
With the current arrangement (a good working one) the compiler "Parallel programmer" with Optimizer "Fastest + pure-code" sends many warnings... don't know if they are significant:

Code:
C:\Users\dell\AppData\Local\Temp\arduino_modified_sketch_26265\TEENSY_Expander_Caricamento_file_Encoders_R1.7.ino:465:16: warning: array subscript is above array bounds [-Warray-bounds]

   pot_value[pot][1] = analogRead(pot);

                ^

In file included from C:\Program Files (x86)\Arduino\hardware\teensy\avr\cores\teensy3/WProgram.h:45:0,

                 from C:\Program Files (x86)\Arduino\hardware\teensy\avr\cores\teensy3/Arduino.h:3,

                 from C:\Users\dell\AppData\Local\Temp\arduino_build_754619\sketch\TEENSY_Expander_Caricamento_file_Encoders_R1.7.ino.cpp:1:

C:\Users\dell\AppData\Local\Temp\arduino_modified_sketch_26265\TEENSY_Expander_Caricamento_file_Encoders_R1.7.ino:466:44: warning: array subscript is above array bounds [-Warray-bounds]

   if (abs(pot_value[pot][1] - pot_value[pot][0]) > isteresi) {

                                            ^

C:\Program Files (x86)\Arduino\hardware\teensy\avr\cores\teensy3/wiring.h:121:19: note: in definition of macro 'abs'

   typeof(x) _x = (x); \

                   ^

C:\Users\dell\AppData\Local\Temp\arduino_modified_sketch_26265\TEENSY_Expander_Caricamento_file_Encoders_R1.7.ino:467:18: warning: array subscript is above array bounds [-Warray-bounds]

     pot_value[pot][0] = pot_value[pot][1];

                  ^

C:\Users\dell\AppData\Local\Temp\arduino_modified_sketch_26265\TEENSY_Expander_Caricamento_file_Encoders_R1.7.ino:465:16: warning: array subscript is above array bounds [-Warray-bounds]

   pot_value[pot][1] = analogRead(pot);

                ^

All these above array bounds indicate you are overwriting other RAM
Note: if declaring an array as A[100], then the index in C/C++ vary from 0 to 99 index=100 is out-of-bound
 
All these above array bounds indicate you are overwriting other RAM
Note: if declaring an array as A[100], then the index in C/C++ vary from 0 to 99 index=100 is out-of-bound

You have hit the mark! Blame on me! There was a trivial out-of-bound writing a vector I had neglected! Finally... After this correction I can swap again the position of any function inside my code.
Thank you!!
Sandro
 
im surprised the compiler doesnt just prevent compiling instead of issueing a warning for out of bounds writing..
 
im surprised the compiler doesnt just prevent compiling instead of issueing a warning for out of bounds writing..

I agree... besides for detecting the mistake the compiler has analized how the vector is addressed... I also dubt about this!.
 
Since the array size might theoretically change at runtime, for example with new() or calloc(), the compiler can not be aware of array indexes out of bound at compile time. That verification can only be done in a reliable way by thoughtful programming.
 
Sometimes the compiler does know this with certainty at compile time.

Maybe we should start using "-Werror=array-bounds" for these cases?
 
Dear Paul and XFer.. I apologize for my ignorance: how pratically use Werror? Is it possible with Arduino IDE, either another compiler is required?
Thank you!
 
Last edited:
Status
Not open for further replies.
Back
Top