The problem below is related to my other recent forum post,
Variable shows NAN after return from function call
I've learned more about what's going on, and decided to start a new thread to succinctly summarize this ongoing strange problem:
In my code, within one of my functions (functionA()), I call another function (functionB( )), which calculates and assigns the values in MyArray[ ], which is an array of doubles that is created and intialized to 0.0 within functionA(). I've verified that the calculated values assigned to MyArray[ ] within functionB( ) are always correct at the very end of functionB().
Immediately upon return from functionB(), back in functionA(), when I print out the values in MyArray(), strange things are happening.
Initially, I had simply had the print statement:
Every time, the value of MyArray always showed NAN instead of a real value (but all other values in MyArray were fine), which led me to think that there was some problem with the actual value of MyArray.Code:printf("Back from functionB(): MyArray = %f, MyArray = %f, MyArray = %f, ...\n", MyArray,MyArray,MyArray,...);
But now that I've added some additional print statements, I've found something odd: When I inserted the following print statements *around* my original one above:
...*all* of the new MyArray values printed out, before and after my original statement, are all fine! And yet the longer print statement above (in the middle of the new additions) continues to show MyArray = NAN.Code:printf("Back from funcB() #1: MyArray = %f.\n", MyArray); printf("Back from funcB() #2: MyArray = %f.\n", MyArray); printf("Back from functionB(): MyArray = %f, MyArray = %f, MyArray = %f, ...\n", MyArray,MyArray,MyArray,...); printf("Back from funcB() #3: MyArray = %f.\n", MyArray); printf("Back from funcB() #4: MyArray = %f.\n", MyArray);
If I substitute MyArray or some other value in for MyArray in the long print statement above, *any* of these other values *also* prints out as NAN! So apparently, there is a problem with whichever first value is being printed in this long print statement, and not specifically a problem with the value of MyArray.
Also, I made a copy of the long print statement above, and pasted it on the next line after my original long print statement. Every value in this 2nd copy is fine, including MyArray. However, if I comment out the original long statement and only allow the copy of this long statement to remain, the first value printed out is now NAN.
I've checked and checked again for a syntax error in my long printf( ) statement, but I haven't found anything...
My code system is fairly complex, so I don't think that including extensive code in this thread is going to be useful or necessary to solve this problem. This *seems* to be a weird but isolated issue... any suggestions about what might possibly be going wrong, such that the value of MyArray could be printed fine before my long print statement above, but then always displays erroneously later on, even though no changes to the values in MyArray[ ] are being made?
Thanks in advance for your input.