A new error appeared when compiling code using the MF_MIDIfile library. I condensed the code to a simple program which exhibits the problem.
typedef struct
{
uint8_t track; ///< the track this was on
uint16_t size; ///< the number of data bytes
uint8_t type; ///< meta event type
union
{
uint8_t data[50]; ///< byte data. Only 'size' bytes are valid
char chars[50]; ///< string data. Only 'size' bytes are valid
};
} meta_event;
#define ARRAY_SIZE(a) (sizeof(a)/sizeof((a)[0]))
void setup(void)
{
uint32_t mLen;
meta_event mev;
mLen = 12;
uint8_t minLen = min(ARRAY_SIZE(mev.data), mLen);
}
void loop(void){
}
If you compile this code for the Arduino Nano ESP32 it gives no error.
If you select the "ESP32 Dev Module", the "ESP32-WROOM-DA module", or the "DOIT ESP32 DEVKIT V1" (and probably others), it compiles with the following error (plus much more):
D:\Util\ArduinoSB\Sketchbook\MF_error\MF_error.ino:23:23: error: no matching function for call to 'min(unsigned int, uint32_t&)'
I am using IDE 2.3.4.
The Dispatcher
Hi @thedispatcher . When compiling for ESP32, both arguments to min must have the same data type:
opened 02:54AM - 25 Apr 22 UTC
closed 01:26AM - 11 May 22 UTC
Status: To be implemented
Status: Solved
### Board
DevkitC ESP32 WROOM
### Device Description
None
### Hardware Confi… guration
No
### Version
latest development Release Candidate (RC-X)
### IDE Name
Arduino 1.8.13
### Operating System
Win 11
### Flash frequency
80MHz
### PSRAM enabled
no
### Upload speed
921600
### Description
Max is not accepting #defined values
The second call to max() fails to compile in ESP32, nut OK in AVR.
Issue occurs in both 2.0.2 and 2.0.3_RC1
### Sketch
```cpp
#define MULT 0.7
void setup() {
float a = 1.1, b = 2.2, c;
c = max(a, b);
c = max(a, MULT);
}
void loop() {
}
```
### Debug Message
```plain
C:\Users\xyzzy.DESKTOP-J4ESB3N\Documents\dad\_microcontroller\esp\esp32\max_test\max_test.ino: In function 'void setup()':
max_test:5:17: error: no matching function for call to 'max(float&, double)'
c = max(a,MULT);
^
In file included from c:\users\xyzzy.desktop-j4esb3n\appdata\local\arduino15\packages\esp32\tools\xtensa-esp32-elf-gcc\gcc8_4_0-esp-2021r2-patch3\xtensa-esp32-elf\include\c++\8.4.0\algorithm:62,
from C:\Users\xyzzy.DESKTOP-J4ESB3N\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.3-RC1\cores\esp32/Arduino.h:155,
from sketch\max_test.ino.cpp:1:
c:\users\xyzzy.desktop-j4esb3n\appdata\local\arduino15\packages\esp32\tools\xtensa-esp32-elf-gcc\gcc8_4_0-esp-2021r2-patch3\xtensa-esp32-elf\include\c++\8.4.0\bits\stl_algo.h:3468:5: note: candidate: 'template<class _Tp, class _Compare> _Tp std::max(std::initializer_list<_Tp>, _Compare)'
max(initializer_list<_Tp> __l, _Compare __comp)
^~~
c:\users\xyzzy.desktop-j4esb3n\appdata\local\arduino15\packages\esp32\tools\xtensa-esp32-elf-gcc\gcc8_4_0-esp-2021r2-patch3\xtensa-esp32-elf\include\c++\8.4.0\bits\stl_algo.h:3468:5: note: template argument deduction/substitution failed:
C:\Users\xyzzy.DESKTOP-J4ESB3N\Documents\dad\_microcontroller\esp\esp32\max_test\max_test.ino:5:17: note: mismatched types 'std::initializer_list<_Tp>' and 'float'
c = max(a,MULT);
^
In file included from c:\users\xyzzy.desktop-j4esb3n\appdata\local\arduino15\packages\esp32\tools\xtensa-esp32-elf-gcc\gcc8_4_0-esp-2021r2-patch3\xtensa-esp32-elf\include\c++\8.4.0\algorithm:62,
from C:\Users\xyzzy.DESKTOP-J4ESB3N\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.3-RC1\cores\esp32/Arduino.h:155,
from sketch\max_test.ino.cpp:1:
c:\users\xyzzy.desktop-j4esb3n\appdata\local\arduino15\packages\esp32\tools\xtensa-esp32-elf-gcc\gcc8_4_0-esp-2021r2-patch3\xtensa-esp32-elf\include\c++\8.4.0\bits\stl_algo.h:3462:5: note: candidate: 'template<class _Tp> _Tp std::max(std::initializer_list<_Tp>)'
max(initializer_list<_Tp> __l)
^~~
c:\users\xyzzy.desktop-j4esb3n\appdata\local\arduino15\packages\esp32\tools\xtensa-esp32-elf-gcc\gcc8_4_0-esp-2021r2-patch3\xtensa-esp32-elf\include\c++\8.4.0\bits\stl_algo.h:3462:5: note: template argument deduction/substitution failed:
C:\Users\xyzzy.DESKTOP-J4ESB3N\Documents\dad\_microcontroller\esp\esp32\max_test\max_test.ino:5:17: note: mismatched types 'std::initializer_list<_Tp>' and 'float'
c = max(a,MULT);
^
In file included from c:\users\xyzzy.desktop-j4esb3n\appdata\local\arduino15\packages\esp32\tools\xtensa-esp32-elf-gcc\gcc8_4_0-esp-2021r2-patch3\xtensa-esp32-elf\include\c++\8.4.0\algorithm:61,
from C:\Users\xyzzy.DESKTOP-J4ESB3N\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.3-RC1\cores\esp32/Arduino.h:155,
from sketch\max_test.ino.cpp:1:
c:\users\xyzzy.desktop-j4esb3n\appdata\local\arduino15\packages\esp32\tools\xtensa-esp32-elf-gcc\gcc8_4_0-esp-2021r2-patch3\xtensa-esp32-elf\include\c++\8.4.0\bits\stl_algobase.h:265:5: note: candidate: 'template<class _Tp, class _Compare> const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
max(const _Tp& __a, const _Tp& __b, _Compare __comp)
^~~
c:\users\xyzzy.desktop-j4esb3n\appdata\local\arduino15\packages\esp32\tools\xtensa-esp32-elf-gcc\gcc8_4_0-esp-2021r2-patch3\xtensa-esp32-elf\include\c++\8.4.0\bits\stl_algobase.h:265:5: note: template argument deduction/substitution failed:
C:\Users\xyzzy.DESKTOP-J4ESB3N\Documents\dad\_microcontroller\esp\esp32\max_test\max_test.ino:5:17: note: deduced conflicting types for parameter 'const _Tp' ('float' and 'double')
c = max(a,MULT);
^
In file included from c:\users\xyzzy.desktop-j4esb3n\appdata\local\arduino15\packages\esp32\tools\xtensa-esp32-elf-gcc\gcc8_4_0-esp-2021r2-patch3\xtensa-esp32-elf\include\c++\8.4.0\algorithm:61,
from C:\Users\xyzzy.DESKTOP-J4ESB3N\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.3-RC1\cores\esp32/Arduino.h:155,
from sketch\max_test.ino.cpp:1:
c:\users\xyzzy.desktop-j4esb3n\appdata\local\arduino15\packages\esp32\tools\xtensa-esp32-elf-gcc\gcc8_4_0-esp-2021r2-patch3\xtensa-esp32-elf\include\c++\8.4.0\bits\stl_algobase.h:219:5: note: candidate: 'template<class _Tp> const _Tp& std::max(const _Tp&, const _Tp&)'
max(const _Tp& __a, const _Tp& __b)
^~~
c:\users\xyzzy.desktop-j4esb3n\appdata\local\arduino15\packages\esp32\tools\xtensa-esp32-elf-gcc\gcc8_4_0-esp-2021r2-patch3\xtensa-esp32-elf\include\c++\8.4.0\bits\stl_algobase.h:219:5: note: template argument deduction/substitution failed:
C:\Users\xyzzy.DESKTOP-J4ESB3N\Documents\dad\_microcontroller\esp\esp32\max_test\max_test.ino:5:17: note: deduced conflicting types for parameter 'const _Tp' ('float' and 'double')
c = max(a,MULT);
```
### Other Steps to Reproduce
Nothing else, simple compile issue.
### I have checked existing issues, online documentation and the Troubleshooting Guide
- [X] I confirm I have checked existing issues, online documentation and Troubleshooting guide.
So you can fix the error by changing this line:
uint32_t mLen;
To this:
unsigned int mLen;
gfvalvo
December 12, 2024, 11:04pm
3
Interesting. The severity of the issue appears to vary with version of ESP32 Arduino Core. Anyway, since sizeof() produces type size_t, best would be:
size_t mLen;
gfvalvo
December 13, 2024, 12:19am
4
You can also provide the template parameter to std::min. This will allow for implicit conversion of the argument types because the template no longer needs to be deduced.
uint32_t mLen;
meta_event mev;
mLen = 12;
uint8_t minLen = min<size_t>(ARRAY_SIZE(mev.data), mLen);
Where would std:min be placed?
The suggestions are welcome. I have only 2 slight misgivings:
I don't like having to change the code of a published library.
"min()" is documented to accept parameters of any type. Should this be changed?
Thanks for the very prompt attention.
The Dispatcher
gfvalvo
December 13, 2024, 5:51pm
6
On ESP32, min() invokes std::min() from the Standard C++ Library (at least it does with ESP32 Arduino Core 3.07 where I tested it). So, the code in Post #4 works as-is.
Any is an overly-strong statement. First, as @ptillisch noted, both parameters must be of the same type. Second, there must actually be a function available that determines which is greater ... min(Serial, Serial1); would be nonsense. You could say without argument that it works for all numeric types ... as long as both are the same type.
system
Closed
June 11, 2025, 5:52pm
7
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.