Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 14 of 14

Thread: Arrangement issue

  1. #1
    Member Sandro's Avatar
    Join Date
    Nov 2016
    Location
    Rimini - Italy
    Posts
    50

    Arrangement issue

    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?
    Thank you

  2. #2
    Senior Member
    Join Date
    Jul 2014
    Posts
    1,878
    compiler or run-time?

  3. #3
    Senior Member DD4WH's Avatar
    Join Date
    Oct 2015
    Location
    Central Europe
    Posts
    304
    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.

  4. #4
    Member Sandro's Avatar
    Join Date
    Nov 2016
    Location
    Rimini - Italy
    Posts
    50
    Quote Originally Posted by WMXZ View Post
    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!

  5. #5
    Member Sandro's Avatar
    Join Date
    Nov 2016
    Location
    Rimini - Italy
    Posts
    50
    Quote Originally Posted by DD4WH View Post
    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

  6. #6
    Senior Member
    Join Date
    Jul 2014
    Posts
    1,878
    Quote Originally Posted by Sandro View Post
    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

  7. #7
    Member Sandro's Avatar
    Join Date
    Nov 2016
    Location
    Rimini - Italy
    Posts
    50
    Quote Originally Posted by WMXZ View Post
    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

  8. #8
    Senior Member
    Join Date
    Dec 2016
    Location
    Montreal, Canada
    Posts
    2,753
    im surprised the compiler doesnt just prevent compiling instead of issueing a warning for out of bounds writing..

  9. #9
    Member Sandro's Avatar
    Join Date
    Nov 2016
    Location
    Rimini - Italy
    Posts
    50
    Quote Originally Posted by tonton81 View Post
    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!.

  10. #10
    Senior Member+ Theremingenieur's Avatar
    Join Date
    Feb 2014
    Location
    Colmar, France
    Posts
    1,905
    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.

  11. #11
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    18,360
    Sometimes the compiler does know this with certainty at compile time.

    Maybe we should start using "-Werror=array-bounds" for these cases?

  12. #12
    Member
    Join Date
    Oct 2015
    Location
    Roma (IT, UE)
    Posts
    71
    That's a good idea Paul, since it looks like a common problem.

  13. #13
    Member Sandro's Avatar
    Join Date
    Nov 2016
    Location
    Rimini - Italy
    Posts
    50
    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 by Sandro; 10-07-2018 at 11:44 AM.

  14. #14
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    18,360
    Quote Originally Posted by Sandro View Post
    how pratically use Werror?
    Edit hardware/teensy/avr/boards.txt to add it to the list of compiler args.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •