I tried to compile the following code [added to the Blink-example]:
template<size_t byteLength>
static int memvcmp(uint8_t const * memory, uint8_t const value)
{
if (0 == byteLength)
{
return 0;
}
else
{
int const firstByteComparison = memcmp(memory, &value, 1);
return (0 == firstByteComparison) ? memcmp(memory, memory + 1, byteLength - 1) : firstByteComparison;
}
}
// the setup function runs once when you press reset or power the board
void setup() {
// initialize digital pin LED_BUILTIN as an output.
pinMode(LED_BUILTIN, OUTPUT);
}
// the loop function runs over and over again forever
void loop() {
digitalWrite(LED_BUILTIN, HIGH); // turn the LED on (HIGH is the voltage level)
delay(1000); // wait for a second
digitalWrite(LED_BUILTIN, LOW); // turn the LED off by making the voltage LOW
delay(1000); // wait for a second
}
It fails with the following error message:
C:\Users...\AppData\Local\Temp.arduinoIDE-unsaved2024103-15436-pctuf.wrhpp\Blink\Blink.ino: In function 'int memvcmp(const uint8_t*, uint8_t)':
C:\Users...\AppData\Local\Temp.arduinoIDE-unsaved2024103-15436-pctuf.wrhpp\Blink\Blink.ino:27:14: error: 'byteLength' was not declared in this scope
if (0 == byteLength)
^~~~~~~~~~exit status 1
Looking into the temporarily generated file it is obvious, that the template-declaration is missing from the implementation:
template<size_t byteLength>
#line 25 "C:\\Users\\...\\AppData\\Local\\Temp\\.arduinoIDE-unsaved2024103-15436-pctuf.wrhpp\\Blink\\Blink.ino"
static int memvcmp(uint8_t const * memory, uint8_t const value);
#line 40 "C:\\Users\\...\\AppData\\Local\\Temp\\.arduinoIDE-unsaved2024103-15436-pctuf.wrhpp\\Blink\\Blink.ino"
void setup();
#line 46 "C:\\Users\\...\\AppData\\Local\\Temp\\.arduinoIDE-unsaved2024103-15436-pctuf.wrhpp\\Blink\\Blink.ino"
void loop();
#line 25 "C:\\Users\\...\\AppData\\Local\\Temp\\.arduinoIDE-unsaved2024103-15436-pctuf.wrhpp\\Blink\\Blink.ino"
static int memvcmp(uint8_t const * memory, uint8_t const value)
{
if (0 == byteLength)
{
return 0;
}
else
{
int const firstByteComparison = memcmp(memory, &value, 1);
return (0 == firstByteComparison) ? memcmp(memory, memory + 1, byteLength - 1) : firstByteComparison;
}
}
Removing the static
keyword from the template declaration solves this problem.
However, as the C++-standard supports static templates, I think the Arduino IDE should not prohibit its use.
Did I do something wrong? Can anyone else confirm this observation? Whom do I have to reach in order for this to be fixed?
Thanks for any feedback
Johannes