RFModulator
Member
I've had a few weird things happen to me with this project I've been working on for the past few months. I'm using a Teensy 3.6 and my code spans across several files, and I use my own Makefile to put it all together. I feel it's impossible to give specific examples since there's too much code for someone to look at (~4000 lines) and it's not feasible to post a snippet that would exemplify the problem. Regardless, I'm hoping someone (who probably knows more than me) could please tell me what they would be suspicious of if they were to see the following behavior:
On three separate occasions, I've had external boolean variables (defined as bool) somehow end up holding the wrong value; that is to say, for example, that when I set a variable to be false and then look at its value later on in the code, I'm seeing a number >0. Each time, I've assured myself that no section of my code that can reassign the boolean's value was being called. I've "solved" each of these occurrences by moving the declaration of the extern variable into a different file. It's hard for me to understand why that would "solve" the problem, and it seems quite odd that this would happen "out of nowhere" when I was not working on any part of the code that had anything to do with the assignment of these variables. Regardless, the problem went from occurring 100% of the time (out of nowhere) to never happening again after I made the modification.
The other thing that just happened to me is that I set a variable to be NULL at the beginning of the program, and when I go to read its value, somehow it is no longer NULL even though I'm certain no part of my code is accessing it or reassigning a different value to it. This part of the program has been working for months. It's not clear at what part of the execution the variable is "losing" its value, and it would be pretty hard to track that down. Again, I wasn't working on any part of the code that had anything to do with this variable when it seemingly started behaving this way.
So, does anybody have any guesses as to what might be going on here? It has me pretty concerned that there might be a big issue afoot, and I wonder if my compiler or linker flags are to blame. I just copied what the Arduino IDE was using to compile Blink.
My cpp files are compiled with:
My c files are compiled with:
And my linker options are:
On three separate occasions, I've had external boolean variables (defined as bool) somehow end up holding the wrong value; that is to say, for example, that when I set a variable to be false and then look at its value later on in the code, I'm seeing a number >0. Each time, I've assured myself that no section of my code that can reassign the boolean's value was being called. I've "solved" each of these occurrences by moving the declaration of the extern variable into a different file. It's hard for me to understand why that would "solve" the problem, and it seems quite odd that this would happen "out of nowhere" when I was not working on any part of the code that had anything to do with the assignment of these variables. Regardless, the problem went from occurring 100% of the time (out of nowhere) to never happening again after I made the modification.
The other thing that just happened to me is that I set a variable to be NULL at the beginning of the program, and when I go to read its value, somehow it is no longer NULL even though I'm certain no part of my code is accessing it or reassigning a different value to it. This part of the program has been working for months. It's not clear at what part of the execution the variable is "losing" its value, and it would be pretty hard to track that down. Again, I wasn't working on any part of the code that had anything to do with this variable when it seemingly started behaving this way.
So, does anybody have any guesses as to what might be going on here? It has me pretty concerned that there might be a big issue afoot, and I wonder if my compiler or linker flags are to blame. I just copied what the Arduino IDE was using to compile Blink.
My cpp files are compiled with:
Code:
-c -O2 -g -Wall -ffunction-sections -fdata-sections -nostdlib -MMD -fno-exceptions -felide-constructors -std=gnu++14 -fno-rtti -mthumb -mcpu=cortex-m4 -mfloat-abi=hard -mfpu=fpv4-sp-d16 -fsingle-precision-constant -D__MK66FX1M0__ -DTEENSYDUINO=140 -DARDUINO=10805 -DF_CPU=48000000 -DUSB_SERIAL -DLAYOUT_US_ENGLISH
Code:
-c -O2 -g -Wall -ffunction-sections -fdata-sections -nostdlib -MMD -mthumb -mcpu=cortex-m4 -mfloat-abi=hard -mfpu=fpv4-sp-d16 -fsingle-precision-constant -D__MK66FX1M0__ -DTEENSYDUINO=140 -DARDUINO=10805 -DF_CPU=48000000 -DUSB_SERIAL -DLAYOUT_US_ENGLISH
Code:
-O2 -Wl,--gc-sections,--relax,--defsym=__rtc_localtime=$(shell date +%s) -lstdc++ -mthumb -mcpu=cortex-m4 -mfloat-abi=hard -mfpu=fpv4-sp-d16 -fsingle-precision-constant -larm_cortexM4lf_math -lm -T"$(LDPATH)/$(MCU_LD)"