So I have this code that I've been running on a Mega 1280 and it's been running fine for a while - slower than I prefer, but otherwise works fine.
I recently got an UDOO, which has a built-in Arduino Due. I went to compile my code for it and it stopped with an error on a line that only contains the following:
int y1=50;
This is one of the very first lines of code. It claims y1 is "redeclared as another symbol" but this is the first time I'm setting it. I'd like to point out that it originally came from a line that looks like this:
int ma=0, x1=50, y1=50, x2=50, y2=50;
If I take out the "y1=50", the rest of the ~300 line code compiles just fine. The code will also compile fine if I choose to compile for the Mega 1280 or 2560.
Any idea why this is happening? Why is it that just y1 is affected?
Nobody knows why the IDE doesn't like y1? I'd like to point out that even if I get rid of all imported libraries, it still fails. I can also just have "int y1;" and it will still fail.
It will not, however, fail if I put it under setup(), but, I want it to be global. Is there a way to fix this?
The error message seems to say exactly what the problem is. One of the ARM toolchain header files declares y1 as a double.
sketch_dec22a:1: error: 'int y1' redeclared as different kind of symbol
/home/me/local/bin/arduino-1.5.5/hardware/tools/g++_arm_none_eabi/bin/../lib/gcc/arm-none-eabi/4.4.1/include-fixed/math.h:365: error: previous declaration of 'double y1(double)'
Ah the error became a lot more easily distinguished when I created a new sketch that just involves "int y1;" - in my complete sketch I got a long list of other unhelpful errors that were a chain reaction of this y1 issue, making the source issue a lot harder to find. Also note that I mainly code in python, where errors are listed in a reverse order, compared to C.
I suppose I could just rename y1 - it is just a name after all and it isn't likely anybody else is going to be looking at it. But it is a variable that I personally would see being relatively common. I can't imagine how many projects out there that use multiple sets of axes, so in my personal opinion, using such a typical name for a variable in something as common as math.h could cause some serious headaches. So for example, what if I really wanted to do a double? I doubt an error would occur, but it could potentially give really wonky results. Personally, I think math.h should rename it to y_0 and y_1, which are a lot less likely to be used. But, instead, I guess I'll be using that pattern.