You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
// Change the code below by your sketch (please try to give the smallest code which demonstrates the problem)
#include<TimeLib.h>voidsetup() {
// put your setup code here, to run once:time_t oneDay = daysToTime_t(1);
}
voidloop() {
// put your main code here, to run repeatedly:
}
Errors or Incorrect Output
~/sketch_jan10a/sketch_jan10a.ino: In function 'void setup()':
~/libraries/Time/TimeLib.h:94:27: error: 'D' was not declared in this scope
#define daysToTime_t ((D)) ( (D) * SECS_PER_DAY) // fixed on Jul 22 2011
^
~/sketch_jan10a/sketch_jan10a.ino:5:19: note: in expansion of macro 'daysToTime_t'
time_t oneDay = daysToTime_t(1);
^
exit status 1
Fix
I am quite new in C/C++ so maybe my fix has some problems, but for me it works.
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
The text was updated successfully, but these errors were encountered: