Open zabojpetr opened 3 years ago
I am experiencing the same issue.
Config: Arduino IDE: 1.8.13 Boards: Uno, ESP8266, ESP32 Compiler __VERSION__ for ESP8266: 4.8.2
Sketch:
#include <TimeLib.h>
void setup() {
uint32_t theTime = minutesToTime_t(5);
}
void loop() { }
Errors:
In file included from Dev/Arduino/sketch_sep21a/sketch_sep21a.ino:1:0:
Dev/Arduino/sketch_sep21a/sketch_sep21a.ino: In function 'void setup()':
Dev/Arduino/libraries/Time/TimeLib.h:92:27: error: 'M' was not declared in this scope
#define minutesToTime_t ((M)) ( (M) * SECS_PER_MIN)
^
Dev/Arduino/sketch_sep21a/sketch_sep21a.ino:4:22: note: in expansion of macro 'minutesToTime_t'
uint32_t theTime = minutesToTime_t(5);
Tests:
Removing the space before the parameter list and the extra set of parens resolves the issue for me:
#define minutesToTime_t ((M)) ( (M) * SECS_PER_MIN)
becomes:
#define minutesToTime_t(M) ( (M) * SECS_PER_MIN)
Additional Info:
Compiling the following program on a Mac with Apple clang version 13.0.0 (clang-1300.0.29.3)
results in the same errors:
#define mFix(M) ( (M) * 60)
#define mOrig ((M)) ( (M) * 60)
int main(int argc, char** argv) {
int m1 = mFix(5);
int m2 = mOrig(5);
return 0;
}
Compiling results in:
testmacro.cpp:6:11: error: use of undeclared identifier 'M'
int m2 = mOrig(5);
^
testmacro.cpp:2:17: note: expanded from macro 'mOrig'
#define mOrig ((M)) ( (M) * 60)
^
testmacro.cpp:6:11: error: use of undeclared identifier 'M'
testmacro.cpp:2:24: note: expanded from macro 'mOrig'
#define mOrig ((M)) ( (M) * 60)
Description
Macros for converting elapsed time to a time_t ends with error:
'parameter' was not declared in this scope
Steps To Reproduce Problem
Call any of Macros for converting elapsed time to a time_t
Hardware & Software
Board: ESP32 Arduino IDE version: 1.8.13 Version info & package name (from Tools > Boards > Board Manager): esp32 1.0.4 Operating system & version Windows 10 (20H2)
Arduino Sketch
Errors or Incorrect Output
Fix
I am quite new in C/C++ so maybe my fix has some problems, but for me it works.
Original
Fixed