Added a function, memory useage drastically changed in strange way.

Hello all!

I have an arduino UNO r3 with an adafruit FONA 800 shield and a few other parts connected. I am using v1.8.9 of the IDE on a windows xp machine (yes the OS is old, but it works :slight_smile: ).

Currently, the code compiles to 18464 bytes, (57%) program space, Global variables use 1320 bytes (64%) dynamic memory.

I wrote a function to scan the SMS slots on the SIM card the FONA is using. Upon compiling, I notice a drastic reduction is memory used. With the added function, now the code compiles at 12568 bytes (38%) program space, Global variables use 731 bytes (35%) dynamic memory. And of course, the function doesn't preform as expected - the for() loop in the function fails to end.

I have attached the code. The code uses the adafruit FONA library that can be found at:

To see this problem, compile the attached code, and note the memory usage. Then remove the comment from the call to the function on line 137, recompile and note memory usage.

The function that is causing the problem is scanSMSSlots(), and starts at line 840.

I am thinking I am running into a memory problem, which is why the for() loop is failing, but I just don't understand the drastic change in memory usage reported by the compiler.

I welcome any help anyone could offer on how to trouble shoot this.

Randy

tstat_v0.2_temp.ino (31.3 KB)

Oops... Things have swapped places here:

tstat_v0.2_temp.ino:847:26: warning: for increment expression has no effect [-Wunused-value]
   for(int i = 1; i ++; i < numOfSlots)  {
                        ~~^~~~~~~~~~~~

oqibidipo:
Oops... Things have swapped places here:

tstat_v0.2_temp.ino:847:26: warning: for increment expression has no effect [-Wunused-value]

for(int i = 1; i ++; i < numOfSlots)  {
                        ^~~~~~~~~~

ooppsss... yes that explains why the for() loop wasn't working. Silly me. I can't believe I missed that. It also fixes the memory usage problem reported by the compiler.

Also, seeing your output prompted me to get into the IDE's user preferences and snoop around more closely. I now know how to get the warnings and such to trouble shoot things like this.

Many thanks, oqibidipo!!

Randy