So I was just handed year old code for arduino, and I can't seem to get it to compile. It was written in the arduino IDE (though I don't know what version)
In file included from c:/.../tools/avr/lib/gcc/../../avr/include/inttypes.h:37,
from C:\...\arduino-0022\libraries\EEPROM/EEPROM.h:23,
from S_Curve.cpp:23:
c:/.../tools/avr/lib/gcc/../../avr/include/stdint.h:121: error: expected initializer before numeric constant
c:/.../tools/avr/lib/gcc/../../avr/include/stdint.h:122: error: expected initializer before numeric constant
c:/.../tools/avr/lib/gcc/../../avr/include/stdint.h:123: error: expected initializer before numeric constant
c:/.../tools/avr/lib/gcc/../../avr/include/stdint.h:124: error: expected initializer before numeric constant
c:/.../tools/avr/lib/gcc/../../avr/include/stdint.h:125: error: expected initializer before numeric constant
c:/.../tools/avr/lib/gcc/../../avr/include/stdint.h:126: error: expected initializer before numeric constant
c:/.../tools/avr/lib/gcc/../../avr/include/stdint.h:128: error: expected initializer before numeric constant
c:/.../tools/avr/lib/gcc/../../avr/include/stdint.h:129: error: expected initializer before numeric constant
c:/.../tools/avr/lib/gcc/../../avr/include/stdint.h:142: error: 'int16_t' does not name a type
c:/.../tools/avr/lib/gcc/../../avr/include/stdint.h:147: error: 'uint16_t' does not name a type
c:/.../tools/avr/lib/gcc/../../avr/include/stdint.h:159: error: 'int8_t' does not name a type
c:/.../tools/avr/lib/gcc/../../avr/include/stdint.h:164: error: 'uint8_t' does not name a type
c:/.../tools/avr/lib/gcc/../../avr/include/stdint.h:169: error: 'int16_t' does not name a type
c:/.../tools/avr/lib/gcc/../../avr/include/stdint.h:174: error: 'uint16_t' does not name a type
c:/.../tools/avr/lib/gcc/../../avr/include/stdint.h:179: error: 'int32_t' does not name a type
c:/.../tools/avr/lib/gcc/../../avr/include/stdint.h:184: error: 'uint32_t' does not name a type
c:/.../tools/avr/lib/gcc/../../avr/include/stdint.h:192: error: 'int64_t' does not name a type
c:/.../tools/avr/lib/gcc/../../avr/include/stdint.h:199: error: 'uint64_t' does not name a type
c:/.../tools/avr/lib/gcc/../../avr/include/stdint.h:213: error: 'int8_t' does not name a type
c:/.../tools/avr/lib/gcc/../../avr/include/stdint.h:218: error: 'uint8_t' does not name a type
c:/.../tools/avr/lib/gcc/../../avr/include/stdint.h:223: error: 'int16_t' does not name a type
c:/.../tools/avr/lib/gcc/../../avr/include/stdint.h:228: error: 'uint16_t' does not name a type
c:/.../tools/avr/lib/gcc/../../avr/include/stdint.h:233: error: 'int32_t' does not name a type
c:/.../tools/avr/lib/gcc/../../avr/include/stdint.h:238: error: 'uint32_t' does not name a type
c:/.../tools/avr/lib/gcc/../../avr/include/stdint.h:246: error: 'int64_t' does not name a type
c:/.../tools/avr/lib/gcc/../../avr/include/stdint.h:253: error: 'uint64_t' does not name a type
c:/.../tools/avr/lib/gcc/../../avr/include/stdint.h:273: error: 'int64_t' does not name a type
c:/.../tools/avr/lib/gcc/../../avr/include/stdint.h:278: error: 'uint64_t' does not name a type
It looks to me like it's trying to compile in C89, but I'm new to arduino, so I'm hoping someone here might have some insight. (and again, this is all from code currently running on the board)
Without seeing the code you are trying to compile, it's hard to say what the problem is, but... do you by any chance have 'extern "C" {...}' around the #include directives in the file? if so, try removing it.
I'm guessing here, but is it any different if you put the #include directives right at the start of the file? The Arduino IDE does some sort of preprocessing on the file before passing it to the compiler, and I'm wondering if it expects #include directives to be at the start.
No matter how I shake up the includes, it will insert it's stuff just before the first function.. And it will rearrange the errors, but still fails.
Is the complete error log, if you're interested.. It just bothers me as it seems to be mostly related to libraries, and not anything in this code. It's throwing errors from the templated functions, but I'm assuming it's for a similar reason. (That is, it still seems to be compiling in C89)
Honestly? Not sure. As I said, I was just given this code. It looks like it's never actually used. I commented it out, and reworked the includes/defines, it now looks like
In file included from C:\...\arduino-0022\hardware\arduino\cores\arduino/WProgram.h:6,
from S_Curve.cpp:6:
c:/.../arduino-0022/hardware/tools/avr/lib/gcc/../../avr/include/math.h:439: error: expected unqualified-id before 'double'
c:/.../arduino-0022/hardware/tools/avr/lib/gcc/../../avr/include/math.h:439: error: expected `)' before 'double'
c:/.../arduino-0022/hardware/tools/avr/lib/gcc/../../avr/include/math.h:439: error: expected `)' before 'double'
S_Curve:22: error: expected ',' or '...' before '&' token
S_Curve:22: error: ISO C++ forbids declaration of 'T' with no type
S_Curve:23: error: 'T' has not been declared
Which once again gets back to it seeming not to support Templates.. But as I said, this code is currently running on the board.
And those lines are what the build chain is inserting:
#include "WProgram.h"
void messageReady();
void soft_Reset();
int EEPROM_writeAnything(int ee, const T& value);
int EEPROM_readAnything(int ee, T& value);
void moveStepper(long steps, char axis1, char dirChar1, char axis2, char dirChar2);
char checkDir(long difference, char axis);
void moveToPos(long x, long y, long z);
void setup();
void loop();
And those T& are taken directly from the playground
I feel like an idiot. pulled out the templates into a separate file (as per the playground) and everything compiles.
As I said, I was just given this this morning, and it worked before, so it didn't even occur to me.
I lied. I now get:
In file included from C:\...\arduino-0022\hardware\arduino\cores\arduino/WProgram.h:6,
from /EEPROMAnything.h:2,
from S_Curve.cpp:9:
c:/.../arduino-0022/hardware/tools/avr/lib/gcc/../../avr/include/math.h:439: error: expected unqualified-id before 'double'
c:/.../arduino-0022/hardware/tools/avr/lib/gcc/../../avr/include/math.h:439: error: expected `)' before 'double'
c:/.../arduino-0022/hardware/tools/avr/lib/gcc/../../avr/include/math.h:439: error: expected `)' before 'double'
I presume that EEPROMAnything.h is your template definition file. Do you explicitly #include WProgram.h at the start of that file? If so, what happens if you comment that out?