Hi,
I ran into an issue where I had a variable, lets call it foo, declared globally in foo.c.
int foo = 0; // this is located globally in foo.c
I then assigned foo.c a variable in main.c
int main(void)
{
foo = 10;
}
The compiler accepted the code and compiled it.
When running my code in debug, everything was fine, until I compiled my code for flash execution and ran it as it would in the field.
My code was not running as expected.
I was able to find that I did not declare foo in main.c.
I then used the bad habit of declaring foo as extern in main.c.
extern int foo; // this was placed into main.c.
Then my code ran as expected when executing out of flash as it would in the field.
My biggest question is, why didn't the compiler refuse to compile the code prior to me declaring foo as an extern variable in main.c?
This shouldn't even be a warning, but a show stopper for the compiler.
I was also able to verify that foo was not declared anywhere else in main.c thinking that maybe it was being resolved to some local variable.
I'm using the C5515 with TI compiler 4.4.1.
After this little run in, I have decided to go through my code and eliminate the use of external variables.
Any input on what I have described would be appreciated.
Thanks!